How to apply if statement in ode45 function?
8 次查看(过去 30 天)
显示 更早的评论
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??
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geometry and Mesh 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!