I am trying to plot this function dpdt = N0*sin(ome​ga*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
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.
Avan Al-Saffar
Avan Al-Saffar 2014년 8월 19일
Here is the error that I got:
Warning: Failure at t=5.381661e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.421085e-14) at time t. > In ode45 at 308 In RunLogistic at 3
Thanks

댓글을 달려면 로그인하십시오.

답변 (1개)

Aykut Satici
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.
  댓글 수: 1
Avan Al-Saffar
Avan Al-Saffar 2014년 9월 17일
I tried your suggestion but I received this error message:
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
Error in ode5>create@(t,p,K,N0,omega)N0*sin(omega*t)*p*(1-p/K)
What is this mean please?
I solved my problem by removing the initial period from my data.
Thank you

댓글을 달려면 로그인하십시오.

카테고리

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