How can I put condition in ode solver
Ältere Kommentare anzeigen
I'm trying to put if condition in ode solver.
but it seems that I can't control variables in ode function. (can control just derivative of variables)
for example
function dcdt = exo(t,c)
dcdt = zeros(3,1)
dcdt(1) = -c(1)*exp(-1/c(3));
if c(1) < 0
c(1) = 0; ----->>> this doesn't work!!!
end
dcdt(2) = -c(2)*exp(-1/c(3));
dcdt(3) = - dcdt(1) + dcdt(2);
end
How can I change this function to make c(1) = 0 if c(1) < 0
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 31 Dez. 2020
0 Stimmen
Use odeset to create an options structure with the NonNegative option set to the elements of the solution that need to remain non-negative and pass that options structure into the ODE solver.
1 Kommentar
kkh1897
am 31 Dez. 2020
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!