How to set a loop in ode45
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!