How to stop, reset the variables and restart an ODE solver?

I am trying to solve a system of equations in which I want to stop the solver at certain t-values, reset the value of depenedent variables, and restart the solver. Is there an example that I can look at and try to mimic?

Answers (1)

Look at ballode and how it uses "events", and observe how it loops calls until the entire time is complete.

5 Comments

I could only find bounceEvents.m but not events.m. Any help will be appreciated.
Which release are you using? In R2019a, the function "events" is at the bottom of ballode.m
In any case, what I was referring to was not a specific function, but rather the Events option . In the version of ballode I am looking at now, close to the top of the file, a variable named options is assigned to using the result of calling odeset() with several parameters, the first of which is 'Events', @events . Perhaps in the version you are looking it it might say 'Events', @bounceEvents . The exact name of the function is not important: the importance is in the 'Events' option and the structure of the function that is called.
Got it. Is it this one?
function [value,isterminal,direction] = events(t,y)
% Locate the time when height passes through zero in a decreasing direction
% and stop integration.
value = y(1); % detect height = 0
isterminal = 1; % stop the integration
direction = -1; % negative direction
Now, if I want the integration to stop and reset the value of the first dependent variable at t=6 (say), do I edit the value or the isterminal?
Is there more documentation about these parameters? I feel like I don't understand how they work so I cannot edit them.
Thanks but I had already looked at it. I still don't understand how I can adapt the following line so that it stops integrating at t=6 and replace dydt(2) to be 40 (say) and starts integrating again.
value = y(1);
I tried to replace it with the following but it doesn't seem to work.
value = t-6;

Sign in to comment.

Tags

Asked:

VR
on 3 Apr 2019

Commented:

VR
on 18 Apr 2019

Community Treasure Hunt

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

Start Hunting!