Stopping ODE solver on zero crossing

  • Context: Graduate 
  • Thread starter Thread starter Lord Crc
  • Start date Start date
  • Tags Tags
    Ode Zero
Click For Summary
SUMMARY

The discussion focuses on implementing an ODE solver using the Runge-Kutta 4th order (RK4) method to find the time at which the solution crosses zero. The user is developing their own RK4 routine in C# and seeks effective methods for detecting zero crossings. A proposed solution involves checking the value of the function after each integration step and adjusting the step size accordingly. Additionally, linear interpolation is suggested as an efficient method to approximate the zero crossing time using the last known values of the function and its derivative.

PREREQUISITES
  • Understanding of ordinary differential equations (ODEs)
  • Familiarity with the Runge-Kutta 4th order (RK4) method
  • Basic knowledge of numerical methods for root finding
  • Proficiency in C# programming language
NEXT STEPS
  • Implement zero crossing detection in RK4 using step size adjustment
  • Explore linear interpolation techniques for root finding
  • Research numerical methods for solving ODEs in C#
  • Learn about adaptive step size methods in numerical integration
USEFUL FOR

Mathematicians, software developers, and engineers working on numerical solutions for ordinary differential equations, particularly those implementing custom ODE solvers in C#.

Lord Crc
Messages
341
Reaction score
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
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.
 
Yes, I'm writing my own RK4 routine in C#.

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

Similar threads

  • · Replies 65 ·
3
Replies
65
Views
9K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 0 ·
Replies
0
Views
4K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K