bounding ODEs to have ZERO values whenever being negative

hello,
I am trying to bound my ODEs so that whenever a negative value is taken it will transform into a zero.
here is my code
function dy = LOGISTICMANAGMENT(t,y)
dy = zeros(5,1);
a = 0.037;
e1 = 50;
c = 0.25;
p = 100;
s = 30;
u = 0.25;
h = 0.8;
dy(1) = a * y(1) * (1 - y(1)); %%Accessibility
dy(2) = e1 * y(1); %%Timber cutting
dy(3) =0.025 * y(4) * (1-0.02672 * y(3))-0.0067 * y(3)-y(2)/2.29 ; %%Dunamics of stratum 1
dy(4) = 0.12 * y(3) * (1-0.0125 * (0.16 * y(3)+0.013 * y(4)))-0.025 * y(4) * (1-0.02672 * y(3))-y(4) * (0.000128 * y(3)+0.0067)-u*y(4)*(1-h); %%Dynamics of stratum 2
dy(5) = 0.066*y(4)*(0.00128*y(3)+0.0067)+0.1*y(2)+0.0153*y(3)*0.19-0.06*y(5); %%Deadwood dynamics
end
If i simulate this function, zero values will be taken which is unrealistic in my case, so thats why i want to bound the ODEs to take ZERO values when negative.
PS: i am new to matlab
Many thanks in advance

Answers (1)

https://de.mathworks.com/help/matlab/math/nonnegative-ode-solution.html
Best wishes
Torsten.

1 Comment

Note that if you are getting the negative values more or less due to round-off error or minor over-prediction then the above solution might work.
However, if you have a situation such as bounding against a wall or falling to the ground where a particular value is a hard boundary that interrupts an otherwise smooth range, then the above solution is not appropriate. Hard boundaries that interrupt computations are not differentiable at the boundary, and the ode integrators can only handle differentiable functions. If you have a boundary like this, then you must use an event function to signal the termination of the ode.

Sign in to comment.

Asked:

on 31 May 2017

Commented:

on 31 May 2017

Community Treasure Hunt

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

Start Hunting!