Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Jan
Jan el 1 de Jul. de 2018
Editada: Jan el 1 de Jul. de 2018
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.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by