How to introduce a constriant and stop condition in ode45 ？
4 views (last 30 days)
There are two questions. The first question is how to introduce a constriant in ode45 for a variable.
For example, the constriant of y(2) is 0<=y(2)<=2 in the following code，and how to introduce it?
The second question is how to introduce a stop condition in ode45？
For example, how to stop the integration of ode45 at two conditions when y(1)<-1 and y(2)<-2 in the following code?
Please give me help. Thanks.
[t, Y] = ode45(@fun,[0:0.1:20], Y0);
Torsten on 8 Jun 2022
Edited: Torsten on 8 Jun 2022
You can't prescribe a constraint for a solution variable of an ODE. The ODE variable results automatically from the ODE equation, so you cannot influence it: either it respects your constraint or not.
Use the "event" facility of the ODE integrators:
More Answers (1)
Jan on 8 Jun 2022
Both is done by an event function. There you can check the values of the current trajectory and stop the integration. If the values should be limited only, you restart the integration from the current location setting the corresponding derivative to 0.