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.
0 件のコメント
採用された回答
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!