MATLAB Answers


Ode45 change of a value in the equations

Asked by Marco Puglia on 30 Oct 2019
Latest activity Commented on by Stephan
on 30 Oct 2019
Hi everybody, I'm new at matlab, and I have a problem with Ode45: This is my system of equations to solve:
[tout,yout] = ode45(@(t,y) EQS(y,m,T,FN,P,D,gamma,tau), ...
dPdt = + m .* T .* FN .* P - gamma .* P
dNdt = - m .* T .* FN .* P + tau .* D
dDdt = + gamma .* P - tau .* D
Ode45 works perfectly for this system but I need to change the parameter T (a vector) after a certain number of steps. How can I do that? I have tried to place loops and statemetns into the function "EQS" but Ode doesn't care about them.


Show 1 older comment
Just once. T has to change from a gaussian with center in 15, to a gaussian with center in 20 after the 365th step.
365th step means t=365 for you?

Sign in to comment.

1 Answer

Answer by Stephan
on 30 Oct 2019
Edited by Stephan
on 30 Oct 2019

Do 2 calls of ode45. The first from tspan=[0 365]. Then use the final result from this as initial condition for the second call with the changed T.


I can't. Yes, it is feasible in that way, but after this initial code, I have to build something with a T that varies periodically from a value to another.
Please share your code so far

Sign in to comment.