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

Respuestas (1)

KSSV
KSSV el 25 de Jul. de 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 comentarios

shiv gaur
shiv gaur el 25 de Jul. de 2021
plot n vs x not t vs x
shiv gaur
shiv gaur el 25 de Jul. de 2021
not working
KSSV
KSSV el 25 de Jul. de 2021
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 el 30 de Ag. de 2021
using index array

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 25 de Jul. de 2021

Comentada:

el 30 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