How to set a loop in ode45

조회 수: 1 (최근 30일)
Shom
Shom 2015년 8월 19일
답변: Walter Roberson 2015년 8월 19일
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 ?

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 19일
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

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by