last value of array

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

Respuestas (1)

Alan Stevens
Alan Stevens el 31 de Ag. de 2021

0 votos

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 comentarios

shiv gaur
shiv gaur el 31 de Ag. de 2021
when we increase time graph disappear t=1400
shiv gaur
shiv gaur el 31 de Ag. de 2021
the more value is coming about 10^19
Alan Stevens
Alan Stevens el 31 de Ag. de 2021
That's a function of your equations!
shiv gaur
shiv gaur el 31 de Ag. de 2021
pl take another example you are request
Alan Stevens
Alan Stevens el 31 de Ag. de 2021
?

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 31 de Ag. de 2021

Comentada:

el 31 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by