# Math Help - Runge-Kutta of Order 4

1. ## Runge-Kutta of Order 4

Good day everyone,

Until now I cannot move on with these two problems. I don't even know where to start . Anywhere, here goes:

1.) At time t, a pendulum makes an angle x(t) with the vertical axis. Assuming there is no friction, the equation of motion is

$mlx''(t)=-mg sin(x(t))$

where m is the mass and l is the length of the string. Use the Runge-Kutta method to solve the differential equation over the interval [0, 2] using M = 40 steps and h = 0.05 if g = 32 ft/sec² and
(a) $l= 3.2$ ft and $x(0) = 0.3$ and $x'(0) = 0$
(a) $l= 0.8$ ft and $x(0) = 0.3$ and $x'(0) = 0$

My concerns for this problem are that
(1) Am i supposed to integrate
$mlx''(t)=-mg sin(x(x))$ so that x'' becomes x' and then proceed with the iteration process?
(2) I am having a hard time trying to figure out the iteration for this problem since x(t) is not represented as an equation.

2.) Predator-Prey model. An example of a system of nonlinear differential equations is the predator-prey problem. Let x(t) and
y(t) denote the population of rabbits and foxes, respectively at time t. The predator-prey model asserts that x(t) and y(t) satisfy

$x'(t)=Ax(t) - Bx(t)y(t)$

$y'(t)=Cx(t)y(t) - Dy(t)$

A typical computer simulation might use the coefficients
A = 2, B = 0.02, C = 0.0002, D = 0.8.
Use the Runge-Kutta method to solve the differential equation over the interval [0, 5] using M = 50 steps and h = 0.1 if
(a) $x(0) = 3,000$ rabbits and $y(0) = 120$ foxes
(b) $x(0) = 5,000$ rabbits and $y(0) = 100$ foxes

I basically have the same concern as the first problem. Both x(t) and y(t) are not represented as equations, but as functions alone.

I just need someone to help me start with the two problems .

2. Originally Posted by zeugma
Good day everyone,

Until now I cannot move on with these two problems. I don't even know where to start . Anywhere, here goes:

1.) At time t, a pendulum makes an angle x(t) with the vertical axis. Assuming there is no friction, the equation of motion is

$mlx''(t)=-mg sin(x(t))$

where m is the mass and l is the length of the string. Use the Runge-Kutta method to solve the differential equation over the interval [0, 2] using M = 40 steps and h = 0.05 if g = 32 ft/sec² and

(a) $l= 3.2$ ft and $x(0) = 0.3$ and $x'(0) = 0$

(a) $l= 0.8$ ft and $x(0) = 0.3$ and $x'(0) = 0$

My concerns for this problem are that

(1) Am i supposed to integrate $mlx''(t)=-mg sin(x(x))$ so that x'' becomes x' and then proceed with the iteration process?

(2) I am having a hard time trying to figure out the iteration for this problem since x(t) is not represented as an equation.

Numerical ODE solvers usually work on ODE's of the form:

$x'(t)=f(t,x)$

The way you get them to operate on higher order ODE's is to turn the ODE into a system of first order ODE's.

Here you have:

$x''(t)=f(x)$ ,

so we put $\bold{x}={\bold{x}_1 \brack \bold{x}_2}={x \brack x'}$

Then:

$
\bold{x}'={x' \brack x''}={x' \brack f(x)}={\bold{x}_2 \brack f(\bold{x}_1)}
$

Now you can use RK4 on this equation.

CB

3. Originally Posted by zeugma
2.) Predator-Prey model. An example of a system of nonlinear differential equations is the predator-prey problem. Let x(t) and y(t) denote the population of rabbits and foxes, respectively at time t. The predator-prey model asserts that x(t) and y(t) satisfy

$x'(t)=Ax(t) - Bx(t)y(t)$

$y'(t)=Cx(t)y(t) - Dy(t)$

A typical computer simulation might use the coefficients

A = 2, B = 0.02, C = 0.0002, D = 0.8.

Use the Runge-Kutta method to solve the differential equation over the interval [0, 5] using M = 50 steps and h = 0.1 if

(a) $x(0) = 3,000$ rabbits and $y(0) = 120$ foxes

(b) $x(0) = 5,000$ rabbits and $y(0) = 100$ foxes

I basically have the same concern as the first problem. Both x(t) and y(t) are not represented as equations, but as functions alone.

I just need someone to help me start with the two problems .

Same idea here:

$
\bold{x}={\bold{x}_1 \brack \bold{x}_2}={x \brack y}
$

Then:

$\bold{x}'={A \bold{x}_1 - B \bold{x}_1 \bold{x}_2 \brack C \bold{x}_1 \bold{x}_2 -D \bold{x}_2}$

CB

4. Originally Posted by CaptainBlack
Numerical ODE solvers usually work on ODE's of the form:

$x'(t)=f(t,x)$

The way you get them to operate on higher order ODE's is to turn the ODE into a system of first order ODE's.

Here you have:

$x''(t)=f(x)$ ,

so we put $\bold{x}={\bold{x}_1 \brack \bold{x}_2}={x \brack x'}$

Then:

$
\bold{x}'={x' \brack x''}={x' \brack f(x)}={\bold{x}_2 \brack f(\bold{x}_1)}
$

Now you can use RK4 on this equation.

CB
Hi CaptainBlack,

Thank you so much for replying. I just have one concern though. Call me stupid, but I just don't know how to do it.
Anyways, how do I plug in the Runge-Kutta equation?

$f_{n+1}=f_n+\frac{h(f_1+2f_2+2f_3+f_4)}{6}$

where

$f_1=f(t_n,y_n)$

$f_2=f(t_n+\frac{h}{2},y_n+\frac{h}{2}f_1)$

$f_3=f(t_n+\frac{h}{2},y_n+\frac{h}{2}f_2)$

$f_4=f(t_n+h,y_n+hf_3)$

I'm sure I can solve for #2 if I just know how to do it in #1

5. Originally Posted by zeugma
Hi CaptainBlack,

Thank you so much for replying. I just have one concern though. Call me stupid, but I just don't know how to do it.
Anyways, how do I plug in the Runge-Kutta equation?

$f_{n+1}=f_n+\frac{h(f_1+2f_2+2f_3+f_4)}{6}$

where

$f_1=f(t_n,y_n)$

$f_2=f(t_n+\frac{h}{2},y_n+\frac{h}{2}f_1)$

$f_3=f(t_n+\frac{h}{2},y_n+\frac{h}{2}f_2)$

$f_4=f(t_n+h,y_n+hf_3)$

I'm sure I can solve for #2 if I just know how to do it in #1
Write the ODE as the vector first order vector ODE:

$\bold{y}'=\bold{f}(t,\bold{y})$

Then the 4th order RK stepping algorithm is:

$\bold{y}_{n+1}=\bold{y}_n+\frac{h(\bold{k}_1+2\bol d{k}_2+2\bold{k}_3+\bold{k}_4)}{6}$

where

$\bold{k}_1=\bold{f}(t_n,\bold{y}_n)$

$\bold{k}_2=\bold{f}(t_n+\frac{h}{2},\bold{y}_n+\fr ac{h}{2}\bold{k}_1)$

$\bold{k}_3=\bold{f}(t_n+\frac{h}{2},\bold{y}_n+\fr ac{h}{2}\bold{k}_2)$

$\bold{k}_4=\bold{f}(t_n+h,\bold{y}_n+h\bold{k}_3)$

Here a bold charater denotes a vector quantity, and the starting value of $\bold{y}_0$ is given by the initial conditions.

From here it is just (vector) arithmetic.

CB

6. By the way, I just would like to confirm regarding the given equation in #1,

$mlx''(t)=-mg sin(x(t))$

Am I right in canceling the "m" in both sides of the equation
? I am also assuming that the x'' would be isolated at the left-hand side of the equation,

$x''=-\frac{g sinx(t))}{l}$

7. Originally Posted by zeugma
By the way, I just would like to confirm regarding the given equation in #1,

$mlx''(t)=-mg sin(x(t))$

Am I right in canceling the "m" in both sides of the equation? I am also assuming that the x'' would be isolated at the left-hand side of the equation,

$x''=-\frac{g sinx(t))}{l}$
Other that the mismatch in opening and closing brackets, that looks OK

$x''=-\frac{g\ \sin(x(t))}{l}$

CB

8. From the RK4 equation, I'm supposed to solve for $k_1,k_2,k_3,$ and $k_4$ to use the equation below:

$y_{n+1}=y_n+\frac{h(k_1+2k_2+2k_3+k_4)}{6}$

I understand that $k_1$ is solved by getting $f(t_n,y_n)$ and that
$f(t_n,y_n)=-\frac{gsin(x(t))}{l}$. From here I don't know how to proceed since I don't know what values to fill in for $x(t)$. Just looking at the equations make me so confused.

9. Originally Posted by zeugma
From the RK4 equation, I'm supposed to solve for $k_1,k_2,k_3,$ and $k_4$ to use the equation below:

$y_{n+1}=y_n+\frac{h(k_1+2k_2+2k_3+k_4)}{6}$

I understand that $k_1$ is solved by getting $f(t_n,y_n)$ and that
$f(t_n,y_n)=-\frac{gsin(x(t))}{l}$. From here I don't know how to proceed since I don't know what values to fill in for $x(t)$. Just looking at the equations make me so confused.