ode event stopping without a zero crossing

I'm having trouble with an ODE45 model I am building and the event function used to terminate the integration. The event function I am using detects a zero crossing (positive direction) to terminate the solver then another function modifies the ode and I'm feeding the end state from the first run into another ode45 call as the initial conditions (similar to ballode example except instead of modifying the initial conditions I am modifying ode).
The first termination occurs correctly but then I am getting a second termination during the subsequent run. The output reports the same event index (ie) as the first run. When I manually run the event function with the terminated state I am finding that the value of the flagged event is not zero.
How can the solver stop and report an event with an event value that is much less than zero?
Any thoughts?

1 Kommentar

Jason Kozmic
Jason Kozmic am 15 Nov. 2018
I'm adding this in case anyone ever comes acrross this question in the future. The problem was the use of anonymous functions to pass paramters to the ODE. After an event is reached the paramters defining the ODE are updated and the ODE restarted. While that also redefined the parameters of the event funciton becuase the event function recieved the paratmers via anonymous function definition it never actually updated the paramters for use.
Regards,

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Steven Lord
Steven Lord am 15 Nov. 2018

0 Stimmen

Yes, changing the values of the variables that were used to create the anonymous function does not change the values of those variables that the anonymous function stored when it was created. As stated in the "Variables in the Expression" section on this documentation page, to change those values you must recreate the anonymous function.

2 Kommentare

Niels8
Niels8 am 20 Dez. 2018
Bearbeitet: Niels8 am 20 Dez. 2018
Does it mean that the variable with zero crossing can only be expressed once and cannot be changed in the middle of the ODE event code?
For example, the intended variable is "value", and the following lines are in the ODE event function.
value = a-b; % (it will stop when a is equal to b)
if a == 100
value = 0;
end
For the code shown above, let's say a = 100 and b = 97. According to the first line, "value" will be 3. But as a is equal to 100, it will be changed to 0. Do you mean that the solver will not stop because "value" has been declared before?
Steven Lord
Steven Lord am 20 Dez. 2018
Show the full text of your event function and show how you call the ODE solver (in a loop, as in ballode?) WIthout that context I'm not sure what you want.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by