How do I calculate the time it takes for a curve to reach a specific x
coordinate (in Matlab). Let's say we have:
dx/dt = x^2 + y^2 and dy/dt = 5.x.y and the curve starts at the point (a,b). With help from ode45
I was able to get the figure of the curve. I need too calculate the time it takes for the curve too reach x = c, (c>a). I've been told that this can be done by interpolation, but I have no idea how to write the code.
Asked
Active
Viewed 54 times
0

horchler
- 18,384
- 4
- 37
- 73
-
have you looked at [`interp1`](http://www.mathworks.com/help/matlab/ref/interp1.html)? – Mark Mikofski Dec 06 '13 at 18:21
-
yes but to be honest, i didn't quit get what i supposed to write as a code. – user3062479 Dec 06 '13 at 18:27
1 Answers
1
Depending on the behavior of your system around c
, using data interpolation methods such as interp1
on the output may or may not work. The more rigorous way to solve this is either with events (see my answers here or here) or by using the single structure output argument form of ode45
in conjunction with deval
and regular data interpolation methods. Both of these use polynomial interpolation methods designed to work with the underlying ODEs. Though more complicated, events are probably the best way to accuratly determine crossing times like your case.