How can I use Runge Kutta to solve coupled first order DE's in Matlab?

  • Context: Graduate 
  • Thread starter Thread starter HoosierDaddy
  • Start date Start date
  • Tags Tags
    Programming Runge kutta
Click For Summary

Discussion Overview

The discussion revolves around using the Runge Kutta method, specifically Heun's method, to numerically solve a system of two coupled first-order differential equations (DEs) in MATLAB. Participants explore the formulation of the equations, the application of the Runge Kutta algorithm, and the specifics of implementing it in code.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant presents two coupled first-order DEs and seeks assistance in implementing the Runge Kutta method in MATLAB.
  • Another participant asks for clarification on the specific Runge Kutta method being used, particularly regarding the variant of RK2.
  • A participant identifies the method being discussed as Heun's method and provides an alternative formulation known as the midpoint method.
  • There is a question about the correct formulation of the RK2 method, specifically whether it should involve k2 - k1 or k2 + k1.
  • Another participant confirms that the initial formulation aligns with Heun's method, despite the different notation used.
  • A later reply discusses the application of Runge Kutta methods to vector equations, referencing Newton's laws of motion as an example.

Areas of Agreement / Disagreement

Participants generally agree on the identification of Heun's method as the approach to be used, but there is some uncertainty regarding the specific formulation of the RK2 method and whether the notation used is correct. The discussion remains unresolved on the exact details of the implementation.

Contextual Notes

There are limitations in the discussion regarding the clarity of the RK2 method's formulation and the specific definitions of variables used in the context of the coupled DEs.

HoosierDaddy
Messages
4
Reaction score
0
Hello All,

I need to utilize a Runge Kutta second order approach to solve two coupled first order DE's simultaneously given some initial conditions and a conservation relationship.

The DE's are as follows:

[tex]\frac{dp}{dt}[/tex] = aq - bp

[tex]\frac{dq}{dt}[/tex] = -aq + bp

Where a and b are constants, a=3, b=4, and the conservation relationship is nt = p(t) + q(t). Here, nt = 3.

I'm having trouble getting the ball rolling with writing the R.K. algorithm for this, will be programming in matlab. I have solved the equations analytically by hand and have found the following:

p(t) = -0.055972e-3t + 3.055972e-4
q(t) = -0.055972e-7t + 3.055972

Any help on how to get started with the Runge Kutta algorithm to solve numerically would be appreciated!
 
Physics news on Phys.org
You have to do a little work before we can help you. What do you know about Runge Kutta methods? About RK2 in particular? Which particular variant of RK2 (there are more than one) are you supposed to use?
 
Not sure exactly whick RK approach it is, we will be incrementing time such that ...

yj+1 = y*j+1 + [tex]\frac{h}{2}[/tex](k2 - k1)

Where y*j+1 = yj + hk1

and k1 = f(xj, yj) and k2 = f(xj+1, y*j+1)

Does this identify which RK2 method I am attempting to use?
 
That is Heun's method.

An alternative is the midpoint method:

[tex]\aligned<br /> y_{j+1} &= y_j + hk_{j+1/2} \\<br /> x_{j+1/2} &= x_j +h/2 \\<br /> y_{j+1/2} &= y_j + hk_j/2 \\<br /> k_j &= f(x_j,y_j) \\<br /> k_{j+1/2} &= f(x_{j+1/2},y_{j+1/2})<br /> \endaligned[/tex]
 
Thanks D H, I believe we are required to use Heun's method. Can I just draw a parallel to Heun's method with my values? i.e. xj = tj, xj+1 = tj+1 = tj + [tex]\Delta[/tex]t?

If this is the case, what would my yj be? Would I have a separate yj for my p and q equations?
 
Consider this set of six differential equations:

[tex]\aligned<br /> \frac {d\mathbf r}{dt} &= \mathbf v \\<br /> \frac {d\mathbf v}{dt} &= \mathbf a_{\text{ext}} \equiv \mathbf F_{\text{ext}}/m<br /> \endaligned[/tex]

In other words, Newton's laws of motion. Another way to look at this is as a six vector:

[tex]\aligned<br /> \mathbf u &= \left[ r_x \, r_y \,r_z \,\,v_x \,v_y \,v_z \right]^T \\<br /> \frac{\mathbf u}{dt} &= \left[ v_x \,v_y \,v_z \,\,a_x \,a_y \,a_z \right]^T<br /> \endaligned[/tex]

Integration techniques such as Runge Kutta can be used on vectors as well as on scalars. Molecular simulations, for example, essentially work on vectors with thousands of elements or more.
 
Last edited:
HoosierDaddy said:
Not sure exactly whick RK approach it is, we will be incrementing time such that ...

yj+1 = y*j+1 + [tex]\frac{h}{2}[/tex](k2 - k1)

Where y*j+1 = yj + hk1

and k1 = f(xj, yj) and k2 = f(xj+1, y*j+1)

Does this identify which RK2 method I am attempting to use?

Are you sure it is k2 - k1 and not k2 + k1?

The full Heun is

k0 = f(xi, yi)
k1 = f(xi + h, yi + hk0)

yi+1 = yi + (1/2 k0 + 1/2 k1)h
 
That is exactly what he is doing, just written a little differently.
 

Similar threads

  • · Replies 65 ·
3
Replies
65
Views
9K
Replies
2
Views
2K
  • · Replies 31 ·
2
Replies
31
Views
8K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
3K
Replies
4
Views
9K
  • · Replies 1 ·
Replies
1
Views
4K