last value of array

22 views (last 30 days)
shiv gaur
shiv gaur on 31 Aug 2021
while solving diff equation what is the last value of column vector
and graph between n vs x
%plot n vs x n vs y
forn=1:10
[t,r]=ode45(@fn,[0 140],[0.01+n 0.01 ])
plot (n,r(:,1))
end
functiondr=fn(t,r)
x=r(1); y=r(2);
dr=zeros(2,1)
dr(1)=x+y;
dr(2)=x-y;
end

Answers (1)

艾伦·史蒂文斯
艾伦·史蒂文斯 on 31 Aug 2021
Do you mean something like this
%plot n vs x n vs y
forn=1:10
[t,r]=ode45(@fn,[0 14],[0.01+n 0.01 ]);
xlast(n) = r(end,1);
ylast(n) = r(end,2);
end
plot(1:n,xlast,'o',1:n,ylast,'s'),grid
xlabel('n'),ylabel('x,y')
legend('last x','last y')
functiondr=fn(~,r)
x=r(1); y=r(2);
dr=zeros(2,1);
dr(1)=x+y;
dr(2)=x-y;
end
5 Comments

Sign in to comment.

Tags

s manbetx 845


Release

R2021a

Community Treasure Hunt

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

Start Hunting!