フィルターのクリア

I am trying to answer my following word problem and I am running in to issues developing a function

2 ビュー (過去 30 日間)
Transcribing this Differential equation is proving difficult for me: dP/dt = (2-0.1t)P
if P(0) = 1000, find a population at t = 5.
Doing this manually is quite easy. My answer is P(5) = 6.31 x 10^6.
Doing it in Matlab is challenging because I am not well versed in it.
My function in 'func1.m': function dP = func1(t, C) dP(1)=C*exp(2*(t)-0.05*(t)^2);
My call: C =1000; t0 = 5; y0 = 0; tspan = [0 100]; [t, C] = ode45('func1', tspan, t0, y0, pyargs()); plot(t, C)
Any assistance would be greatly appreciated.

採用された回答

Jan
Jan 2018 年 7 月 1 日
編集済み: Jan 2018 年 7 月 1 日
dP/dt = (2-0.1t)P as code:
function dP = finc1(t, P)
dP = (2 - 0.1 * t) * P;
end
And the function to integrate it:
P0 = 1000;
t0 = 0;
tEnd = 5;
tspan = [t0, tEnd];
[t, P] = ode45(@func1, tspan, P0);
plot(t, P)
Provide the function to be integrated as function handle with a leading @..., not as string. The latter works for backward compatibility with R5.3, such the it is outdated for almost 20 years now.
  2 件のコメント
JB
JB 2018 年 7 月 1 日
Jan: Thank you. This will help me gain deeper insights in to the use of Matlab.
V/R jb
JB
JB 2018 年 7 月 1 日
finc1 -> func1 in the function above. :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by