how to plot by varying initial conditions

%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

답변 (1개)

KSSV
KSSV 2021년 7월 25일

0 개 추천

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

shiv gaur
shiv gaur 2021년 7월 25일
plot n vs x not t vs x
shiv gaur
shiv gaur 2021년 7월 25일
not working
KSSV
KSSV 2021년 7월 25일
This is the plot obtained. n is a single number, how you can plot? Plot wrt to t and go for legend. Check is code giving correct results.
shiv gaur
shiv gaur 2021년 8월 30일
using index array

댓글을 달려면 로그인하십시오.

카테고리

제품

릴리스

R2021a

태그

질문:

2021년 7월 25일

댓글:

2021년 8월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by