How to set a loop in ode45
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am new to matlab and am facing a problem while solving a particular differential equation .
My functions is:
function xdot = test(t,x,);
N = 10 ;
a = 0.5 ;
xdot = 2*a*x(1)*(1 - x(1)/N );
and solver is :
x0 = 0.4;
tspan=[0 100];
[t,x]=ode45('test',tspan,x0);
plot (t,x);
Now what do i have to do if i want to set a for loop and varry the values of N from 1 to 10 and solve the diff equation 10 different times for these 10 different value of N and obtain 10 different graphs for the 10 reults ?
0 comentarios
Respuestas (1)
Walter Roberson
el 19 de Ag. de 2015
a = 0.5 ;
test = @(t,x,N) 2*a*x(1)*(1 - x(1)/N );
x0 = 0.4;
tspan=[0 100];
for N = 1 : 10
[t,x] = ode45( @(t,y) test(t,y,N),tspan,x0);
figure
plot (t,x);
title(sprintf('N = %f\n', N));
end
0 comentarios
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!