0

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.

horchler
  • 18,384
  • 4
  • 37
  • 73

1 Answers1

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.

Community
  • 1
  • 1
horchler
  • 18,384
  • 4
  • 37
  • 73