How to set a loop in ode45
조회 수: 1 (최근 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!