last value of array

조회 수: 4 (최근 30일)
shiv gaur
shiv gaur 2021년 8월 31일
댓글: Alan Stevens 2021년 8월 31일
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
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

답변 (1개)

Alan Stevens
Alan Stevens 2021년 8월 31일
Do you mean something like this
%plot n vs x n vs y
for n=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')
function dr=fn(~,r)
x=r(1); y=r(2);
dr=zeros(2,1);
dr(1)=x+y;
dr(2)=x-y;
end
  댓글 수: 5
shiv gaur
shiv gaur 2021년 8월 31일
pl take another example you are request
Alan Stevens
Alan Stevens 2021년 8월 31일
?

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

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by