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!