# Coupled First Order Equations

1. Jul 30, 2010

### Jwill

1. The problem statement, all variables and given/known data
I have a large project involving Runge Kutta numerical solutions of differential equations. I understand the Runge Kutta method and I've done it before, but my problem involves taking the differential equation

y''=sin(3y(t)), t>=0

and reexpressing this IVP into coupled first order equations. I have seen examples where people have done something similiar like set

z'=sin(3y(t))
y'=z

and there is a guy in my class that swears that this is right, but frankly that doesn't make sense to me in this case. If someone could help me understand how to do this correctly, I feel like I have a decent understanding of the numerical solution method. I have been asked to use the first order Runge Kutta method, but I have never used this method with coupled equations that looks anything like this...

2. Relevant equations
y''=sin(3y(t)), t>=0

3. The attempt at a solution
Matlab Code:
clc;
clear all;
close all;
format long g;

N=input('current value of N')
deltat=20./N;
y=1;
z=0;
h = deltat;
t = 0:h:20;
i=0;

for i = 1:length(t)
T(i) = i*h;
Y(i) = y;
k1 = (z);
l1 = sin(3.*(y));
k2 = ((z)+(h./2).*l1);
l2 = sin(3.*((y)+(h./2).*k1));
k3 = ((z)+(h./2).*l2);
l3 = sin(3.*((y)+(h./2).*k2));
k4 = ((z)+h.*l3);
l4 = sin(3.*(y+h.*k3));
z = z + (h./6).*(l1+2.*l2+2.*l3+l4);
y = y + (h./6).*(k1+2.*k2+2.*k3+k4);
end

Y = Y'

plot(T,Y);
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution

2. Jul 30, 2010

### gomunkul51

Mathematical way to do it is:

change the parameters so:
u=y
v=y'

u'=v : first 1st order equation.

v'=sin(3*u) : second 1st order equation.

now you have a system of two 1st order differentials equations.
it's done basically by a change of variables :)

3. Jul 30, 2010

### Jwill

Can someone tell me how to solve this differential equation in matlab so that I can check my numerical solution? (I'm not asking for an answer, just a way to check my answer)

4. Jul 30, 2010

### sshzp4

Look up the help docs for ODE45/23/etc for a way to solve this in matlab. You will find all the examples convert the second order diff eq to two first order or even three. You already have what you need to pretty much copy and paste matlab example code and run your problem. This in control theory is described as the 'state space representation'.

What that friend of yours is doing is converting the second order diff eq, to two first order diff eqs (as gomunk51 already mentioned). Then it's easy to convert things to the RK4 form. You also have a couple of other varieties of RK which do the job based on your requirement for accuracy, precision and time-to-run. See Kreyszig-Engg math. You also have the modified RungeKutta-Nystrom method described there, which generalizes the standard RK method to apply to a second order ODEs

What you have done looks all right, but I don't remember rk4 in detail.

5. Jul 31, 2010

### Jwill

If these equations are correct then I must not understand how to do the stage constants for the iteration.

If
$$\frac{dz}{dt} = sin(3y(t))$$

$$\frac{dy}{dt} = z$$

then

$$\frac{dz}{dt} = f[t, y(t)]$$

$$\frac{dy}{dt} = f[t, z(t)]$$

(I think)

How are they "coupled" in that I don't see that they have a dependency on each other. I understand the runge kutta method when they have a dependency on each other, but how does solving for z or y help you solve for the other?... I don't see how the stage constants rely on each other.

I would understand if it was

$$\frac{dy}{dt} = f[t, y(t), z(t)]$$

$$\frac{dz}{dt} = F[t, y(t), z(t)]$$

If you could help me understand this, I'd appreciate it. It would make since if y and z were in both first order equations.

6. Jul 31, 2010

### Jwill

Well.... anyway my attempt at this was:

$$k1 = z_{i}$$

$$l1 = sin(3.*(y_{i}));$$

$$k2 = z_{i}+\frac{h}{2}*l1$$

$$l2 = sin(3*(y_{i}+\frac{h}{2}*k1))$$

$$k3 = z_{i}+\frac{h}{2}*l2$$

$$l3 = sin(3*(y_{i}+\frac{h}{2}*k2))$$

$$k4 = z_{i}+h*l2$$

$$l4 = sin(3*(y_{i}+h*k2))$$

$$z_{i+1} = z_{i} + \frac{h}{6}*(l1+2*l2+2*l3+l4)$$

$$y_{i+1} = y_{i} + \frac{h}{6}*(k1+2*k2+2*k3+k4)$$

I doubt this is correct... In the event that it is, could someone explain it to me better. Either way, I would like to understand this.

7. Aug 1, 2010

### HallsofIvy

Staff Emeritus
No, this is incorrect.

This is correct.

8. Aug 1, 2010

### Jwill

Okay. I might be on to something with this:

$$u = y$$

$$v = y'$$

$$v' = sin(3u)$$

$$u' = \frac{-1}{3v} cos(3u)$$

This way it's in the form:

$$\frac{dv}{dt} = f$$

$$\frac{du}{dt} = F[v, u]$$

So.... during runge kutta iterations, I'd have to solve for v to solve for u for each iteration.

Is this on the right track? It makes more sense to me anyway... assuming I did the itegration right. I'm not sure if or how I'd do anything with time t though in the stage constants.

9. Aug 1, 2010

### Jwill

Actually, I'm sure that

$$u' = \frac{-1}{3v} cos(3u)$$

is not correct. When I differentiate it, it does not work out to be the original equation. What method of integration would be used to solve it? I'm sure it's integrated over time and v and u are functions of time.

10. Aug 1, 2010

### Jwill

When you said that the two first order functions were incorrect... I am confused because you said that was correct earlier. I am confused and not sure what to do. I don't see how one could use the runge kutta method with those functions.

I am under the impression that in many cases when you use runge kutta, you integration a high order function and form two functions of 2 or 3 variables.

It feels like if I took the function and integrated it and used both of these to solve each equation simultaneously, I could come out with an answer for y. What I tried to do sort of makes sense, but I don't think the integral is right. Any guidance is much appreciated.