How to apply if statement in ode45 function?

1 visualización (últimos 30 días)
kkh1897
kkh1897 el 19 de Oct. de 2020
Comentada: kkh1897 el 19 de Oct. de 2020
I have a multiple equations with variables c1, c2, c3.
Each variables decrease as the time increases.
And I want to put if statement in the function of ode for example "If c1 < 0, then c1 = 0."
I tried as follows:
[t, c] = ode45(@(t,c) myode(t,c), tspan, c0);
function dcdt = myode(t,c)
dcdt = zeros(3,1);
if c(1) < 0
c(1) = 0
end
dcdt(1) = ...
dcdt(2) = ...
dcdt(3) = ...
end
====> It doesn't work : How could I apply if statement properly in this case??

Respuestas (1)

Stephen23
Stephen23 el 19 de Oct. de 2020
c = max(0,c);
  1 comentario
kkh1897
kkh1897 el 19 de Oct. de 2020
where can I put c=max(0,c)?
In the function? or before ode45 expression?
Can you explain it in detail?
Thank you

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by