Stopping ODE solver on zero crossing

  • Thread starter Lord Crc
  • Start date
  • Tags
    Ode Zero
In summary, the conversation discusses using RK4 to solve an initial-value ODE and finding t_end so that x(t_end) = 0. The speaker is having difficulties with stopping the integration and suggests using linear interpolation as a possible solution. They also mention writing their own RK4 routine in C# and considering checking for zero crossings after each integration step.
  • #1
Lord Crc
343
47
Hi,

I'm trying to solve an initial-value ODE using RK4, say dx/dt = f(x,t), x(0) = x0. I want to find t_end so that x(t_end) = 0.

The basic RK4 implementation works fine, however I'm having some difficulties with stopping it in time. I've tried googling around but all I could find was references to MATLAB or similar, which doesn't say anything about how the zero crossing is detected and handled.

The immediate way I can think of is to check after each integration step if x(t) has crossed, and if so restart the step using say half the step length, repeating until it no longer crosses, x(t) = 0 or the step length is below some minimum. Is this an acceptable solution? Are there some better ways?

Cheers!
 
Physics news on Phys.org
  • #2
Do you write your own RK4 program or you use some sort of built-in functions like ode23 in matlab, etc.

If approximate answer is acceptable, I suggest you use linear interpolation. Suppose that the last coordinate is (T, x(T)) before the graph cross the axis. Let find dt such that x(T+dt) = 0.

By Taylor expansion, x(T) + x'(T) dt = 0.
Hence, T+dt = T - x(T)/x'(T) is the approximate time for the zero crossing.
 
  • #3
Yes, I'm writing my own RK4 routine in C#.

Thanks for the linear interpolation suggestion. I'll check it out :)
 

FAQ: Stopping ODE solver on zero crossing

What is an ODE solver?

An ODE solver is a computer algorithm or program used to numerically solve ordinary differential equations (ODEs). These equations describe the relationship between a function and its derivatives, and are commonly used in many scientific and engineering applications.

What does it mean to stop an ODE solver on a zero crossing?

Stopping an ODE solver on a zero crossing means to terminate the solver when the solution of the ODE reaches a point where the function crosses the x-axis and becomes zero. This can be useful when studying dynamic systems that exhibit oscillatory behavior, to capture the exact moment when the function changes direction.

Why would you want to stop an ODE solver on a zero crossing?

Stopping an ODE solver on a zero crossing can be useful in many scenarios. For example, it can help identify critical points or bifurcation points in a system, which can provide valuable insights into the behavior of the system. It can also be used to accurately measure the period of oscillations in a system.

How does stopping an ODE solver on a zero crossing affect the accuracy of the solution?

The accuracy of the solution may be affected when stopping an ODE solver on a zero crossing, as the solver will terminate before reaching the exact solution of the ODE. However, this can be mitigated by choosing a small enough time step or using a more advanced ODE solver that can handle zero crossings more accurately.

Are there any limitations to stopping an ODE solver on a zero crossing?

Yes, there are some limitations to stopping an ODE solver on a zero crossing. For example, it may not work well for systems with highly nonlinear behavior or when the function crosses the x-axis multiple times within a single time step. In these cases, alternative methods such as event detection or adaptive time stepping may be more suitable.

Back
Top