ODE 45 Extra parameter

7 ビュー (過去 30 日間)
See Goo
See Goo 2022 年 8 月 23 日
回答済み: Torsten 2022 年 8 月 23 日
Hello
I hope you're well.
I am currently trying to plot with ODE45. This is a linear growth model.
My formula is (r*p*(1-p/N)) - ((200/2)*(1+sin(2*pi*t)/12))
ODE45 works fine when solving with just the first part of the formula
sol = ode45(@(t,p) (r*p*(1-p/N)) , tspan, p0);
however I am not sure how to implement the extra bit of code. I tried the following
sol = ode45(@(t,p) (r*p*(1-p/N)) - ((200/2)*(1+sin(2*pi*t)/12)), tspan,p0);
But dont think this is correct.
I'm not sure how to implement this extra bit. Would appreciate any help.
Thanks.
Kind regards,
  3 件のコメント
Steven Lord
Steven Lord 2022 年 8 月 23 日
Is there something in particular that leads you to doubt the answer you receive when you run your code? If so can you show us your code and explain your doubt in more detail?
See Goo
See Goo 2022 年 8 月 23 日
編集済み: See Goo 2022 年 8 月 23 日
Thank you for the responses.
I am asked to run only for 15 instances, which represent 15 years.
The first and second case look identical except for after the 15 years time frame where i see some sinusoidal activity.
%Q1
tspan = [0 15];
p0 = 1000 + 1000*2;
r = 0.25;
N =20000;
ode = ode45(@(t,p) r*p*(1-p/N), tspan,p0);
t = linspace(0,15);
devals = deval(ode,t);
plot(t,devals);
xlabel('t');
ylabel('p');
%Q2
tspan = [0 15];
p0 = 1000 + 1000*2;
r = 0.25;
N =20000;
ode = ode45(@(t,p) r*p*(1-p/N) - ((200/2)*(1+sin(2*pi*t)/12)), tspan,p0);
t = linspace(0,15);
devals = deval(ode,t);
plot(t,devals);
xlabel('t');
ylabel('p');

サインインしてコメントする。

採用された回答

Torsten
Torsten 2022 年 8 月 23 日
I think there is quite a noticable difference between the solution curves.
%Q1
tspan = [0 15];
a = 1000 + 1000*2;
r = 0.25;
N =20000;
options = odeset('RelTol',1e-12,'AbsTol',1e-12);
[t,ode] = ode45(@(t,p) r*p*(1-p/N), tspan,a,options);
plot(t,ode)
hold on
%t = linspace(0,15);
%devals = deval(ode,t);
%plot(t,devals);
%xlabel('t');
%ylabel('p');
%Q2
tspan = [0 15];
a = 1000 + 1000*2;
r = 0.25;
N =20000;
[t,ode] = ode45(@(t,p) r*p*(1-p/N) - ((200/2)*(1+sin(2*pi*t)/12)), tspan,a,options);
plot(t,ode)
hold off
%t = linspace(0,15);
%devals = deval(ode,t);
%plot(t,devals);
xlabel('t');
ylabel('p');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by