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