How to set a loop in ode45

6 vues (au cours des 30 derniers jours)
Shom
Shom le 19 Août 2015
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 ?

Réponses (1)

Walter Roberson
Walter Roberson le 19 Août 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

Community Treasure Hunt

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

Start Hunting!

Translated by