how to plot by varying initial conditions

3 views (last 30 days)
shiv gaur
shiv gaur on 25 Jul 2021
Commented: shiv gaur on 30 Aug 2021
%plot n vs x n vs y
for n=1:10
[t,r]=ode45(@fn,[0 140],[0.01+n 0.01 ])
plot (n,r(:,1))
end
function dr=fn(t,r)
x=r(1); y=r(2);
dr=zeros(2,1)
dr(1)=x+y;
dr(2)=x-y;
end
pl plot n vs x

Answers (1)

KSSV
KSSV on 25 Jul 2021
function myfun()
%plot n vs x n vs y
R = cell(10,1) ;
figure
hold on
for n=1:10
[t,r]=ode45(@fn,[0 140],[0.01+n 0.01 ]) ;
R{n} = r(:,1) ;
plot(t,R{n})
end
end
function dr=fn(t,r)
x=r(1); y=r(2);
dr=zeros(2,1) ;
dr(1)=x+y;
dr(2)=x-y;
end
  4 Comments

Sign in to comment.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by