Using event function in matlab ode45 for multi-dimensional state vector

4 views (last 30 days)
Hello, I have a set of odes written in matrix form as Xdot = AX; I also have a desired value of the states X_des. X is a five dimensional vector. I want to stop the integration after all the states reach their desired values (or atleast close to them by 1e-3). How do I use event function in matlab to do this? (All the help I have seen are about 1 dimensional states)
PS: I know for sure that all the states approach their desired values after long time. I just want to stop the integration once they are 1e-3 within the desired values.

Answers (1)

Steven Lord
Steven Lord on 6 Jul 2018
For the original question, consider the maximum difference between the current state and the desired steady state. When that maximum difference crosses your "close enough" threshold of 1e-3 in a downward direction, stop. Since the maximum difference is less than 1e-3, so are all the others.
For the new question asked by max gilles, the Events function can return a vector. See for example the orbitode example. In that case only one of the events is terminal, the other is simply logged and used to plot maximum distance after the ODE solver has completed its work.

Products

Community Treasure Hunt

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

Start Hunting!