I am trying to plot this function dpdt = N0*sin(omega*t)*p*(1-p/K); but I got an error, Please could anyonre help me to solve this error?
조회 수: 1 (최근 30일)
이전 댓글 표시
The code that I am using to plot the previous logistic growth model is :
function RunLogistic
[t,x]=ode45(@logistic42,[0 200],0.1,[],10,10,1);
plot(t,x,'-')
save dodo.mat
1;
I tried to change the solver because may be the error belong to stiff and non-stiff problem but it does not work.
Note: I need to plot the result with the same value for omega,tspan,K and N0.
댓글 수: 2
Geoff Hayes
2014년 8월 19일
Avan - what is the error that you are observing? Is logistic42
dpdt = N0*sin(omega*t)*p*(1-p/K);
or something else? Please attach all relevant code.
답변 (1개)
Aykut Satici
2014년 8월 19일
The built-in ODE solvers in MATLAB are all variable-step methods. This means they have an adaptive method for selecting how big of a time step they are going to take at a given point along the integration routine, see, for instance
Essentially, if they detect the solution changing more and more rapidly, they are going to take smaller and smaller steps.
One way to circumvent this, is to use fixed-step solvers. I have attached a few such solvers in this answer. These solvers do not change the step they take at each point in time.
Now, mathematically, if the right hand side of the differential equation is "smooth enough" all of these fixed steps solvers will converge to the real solution (which can be shown to exist and to be unique) as the time step goes to zero. Therefore, you may need to make the time step small to get it to converge, which would mean it may take a longer time for the integration to complete.
In your case, however, this is not really the case. I have implemented it for you, and it works just fine. Extract the file "ode5.m" from the zip file I have attached to this email and execute the following commands:
t = 0:0.01:50;
f = @(t,p,K,N0,omega) N0*sin(omega*t)*p*(1-p/K)
p = ode5(f,t,0.1,10,10,1);
plot(t,p)
Note that the syntax for "ode5.m" is similar but a little bit different than that of "ode45". You should check out "help ode5" before using it.
참고 항목
카테고리
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!