Solving Non-Linear ODEs with RK4 Method: Time Step Considerations

  • Thread starter RandomGuy88
  • Start date
  • Tags
    Rk4 Time
In summary, the conversation discusses a problem with implementing the 4th Order Runge Kutta (RK4) algorithm for solving a non-linear ODE with time-dependent coefficients. The values of the k coefficients are found to be large, causing numerical instability when using a larger time step. One suggestion is to take constant values for the coefficients and analyze the problem using a phase-plane diagram. It is also mentioned that the issue may be with choosing appropriate initial conditions for the solution.
  • #1
RandomGuy88
406
6
Hi,

I am having a problem implementing 4th Order Runge Kutta (RK4) to solve a non linear ODE.

dy/dt = B(t) - A(t)*y(t)^2 where the coefficients A(t) and B(t) are specific to the problem I am working on.

For the test case I am running I specify a sinusoidal signal and from this signal I calculate A(t) and B(t). While the magnitudes of these coefficients are functions of time they are not functions of the frequency of the sinusoidal function I am specify. I am sure you are all familiar with the algorithm but having it will help me explain.

y(i+1) = y(i) + h/6*(k1 + 2k2 + 2k3 + k4)

k1, k2, k3 and k4 are functions of A(t), B(t) and y(t). As I mentioned above the coefficients A and B are not functions of the frequency of the sinusoid so the values of k1, k2, k3 and k4 are also not functions of the frequency.

My problem is that the values of the k coefficients are quite large. So when I use a high frequency signal the large values of k are compensated by the very small value of h so that the second term on the right hand side h/6*(k1 ...) is the same order of magnitude as y(i). If the frequency is small then I would think I could use a larger timestep h but the k coefficients are still very large so h/6*(k1 ...) >> y(i) and the method is unstable.

Is there anything I can do other than just using a very small time step for the low frequency cases? Perhaps some way of scaling the coefficients? Or should I just use a different method? It just seems wrong that for a lower frequency I need a smaller time step.

Thanks for your help.
 
Physics news on Phys.org
  • #2
Consider what happens if you take make A and B constants in time. This is the ultimate low frequency approximation.

For instance let both A and B =1

Then your equations has the solution [itex] \frac{\left|y+1 \right|}{\left|y-1\right|}=Ae^{2t} [/itex]

Notice that the solution is divided into three distinct regions [itex] y>1 [/itex], [itex] -1<y<1 [/itex] and [itex] y<-1 [/itex]. Your solution should not cross from one region into another. Solutions in these three regions are distinct.


However if your time step is too large, than you RK4 method will calculating k2,k3,k4 from multiple regions. This will give you an erroneous result. I don't know if this is the root cause of your numerical instability... but it does place limits on how large your time step can be.
 
  • #3
The "size" of the ##k## coefficients is not a stability issue in itself. If you solve the same problem in different units, the numerical value of coefficients will change but the number of time steps required for a stable solution will not.

I suggest you take constant values of ##A## and ##B## as in post #2, and make a phase-plane diagram (a plot of ##y'## against ##y##) for different values of ##A## and/or ##B##. You can plot that direct from your differential equation, and also try to reproduce the curves with your numerical solution.

The analysis in #2 might be the explanation of what is going on. The situation may be worse than that, because if ##A## and ##B## are time-dependent, the boundaries between the regions will also be functions of time, which may force the solution of the DE to go to infinity if it can't be a continuous function that crosses the boundary.

Assuming your DE represents the physics correctly, the real problem might be choosing the correct initial conditions for your solutions. You might consider integrating the solution backwards in time, if it's easier to choose physically sensible conditions at the final value of ##t##.
 

1. What is RK4 Time step?

RK4 Time step is a numerical method used in scientific computing to approximate the solutions of differential equations. It is a fourth-order Runge-Kutta method that uses a fixed step size to iteratively solve the equations.

2. How does RK4 Time step work?

RK4 Time step works by taking the initial conditions of a system and using a series of calculations to approximate the value of the system at a given time step. These calculations involve evaluating the derivative at multiple points within the time step and using a weighted average to determine the next value of the system.

3. What are the advantages of using RK4 Time step?

RK4 Time step is a popular method for solving differential equations because it is relatively simple to implement and has a high degree of accuracy. It also has a low computational cost compared to other methods, making it a practical choice for many scientific applications.

4. How is the time step size chosen for RK4 Time step?

The time step size for RK4 Time step is typically chosen based on the desired accuracy of the solution and the stability of the system. A smaller time step size will result in a more accurate solution, but it will also increase the computational cost. It is important to choose a time step size that is small enough to ensure stability but large enough to be computationally efficient.

5. Can RK4 Time step be used for all types of differential equations?

RK4 Time step can be used for a wide range of differential equations, including both ordinary and partial differential equations. However, it may not be the most efficient method for all types of equations. It is important to consider the specific characteristics of the equation and the desired accuracy when choosing a numerical method.

Similar threads

  • Programming and Computer Science
2
Replies
36
Views
3K
Replies
2
Views
2K
Replies
5
Views
366
Replies
7
Views
2K
Replies
56
Views
685
  • Differential Equations
Replies
3
Views
1K
Replies
3
Views
795
  • Programming and Computer Science
Replies
15
Views
2K
  • Differential Equations
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
Back
Top