How can I solve a differential equation on non-fixed interval?

I am trying to solve a first order ODE with such conditions: y(0) = 0, y(x_0)=1,
where x_0 must be determined with the last condition. Therefore I have to be solving the ODE until y=1. But MATLAB requires setting of all integration interval before solving.
The trivial way is to change the interval on fixed step each time when y does not achieve 1 and to solve the equation again. But this method takes a lot of time for calculations.
Is there any different way to solve a ODE on non-fixed interval?

 Accepted Answer

Use the "Event"-facility of the ODE-integrators and stop integraton if y=1.
Example under
https://www.mathworks.com/examples/matlab/mw/matlab-ex84325677-simple-event-location-a-bouncing-ball
Best wishes
Torsten.

1 Comment

Thanks, Torsten. I've made this.
Also here is detail explanation https://www.mathworks.com/help/matlab/math/ode-event-location.html

Sign in to comment.

More Answers (0)

Asked:

on 14 Jun 2017

Commented:

on 14 Jun 2017

Community Treasure Hunt

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

Start Hunting!