# Second order ODE (numerical)

1. Apr 23, 2005

### eckiller

Suppose we have y'' = f(t, y); y(a) = y0; y'(a) = y0'
Note all derivatives are with respect to t.

Let u = y', then u' = y''

1. u' = f(t, y), u(a) = y'(a)
2. y' = u, y(a) = y0

Question 1: For y' = u, should I think of this as dy/du = u? Otherwise, I don't see how to solve 2 because what is u as a function of t?

So I pump both (1) and (2) through a numerical ODE solver.

For (1) I get answer u(t), and for (2) I get answer y(t) ? That doesn't seem right, as y(t) is what I want. How do I put my two answers together to get y(t).

As you can probably tell, I'm very confused on this.

2. Apr 23, 2005

### saltydog

So for:

$$y^{''}=f(x,y)$$

Let:

$$y^{'}=v(x)$$

$$v^{'}=f(x,y)$$

Now you have two first-order ODEs just right for Runge-Kutta or other methods. To start the numerical method, y(a)=$y_0$ and v(a)=y'(a).

When you get the results, you get two separate (numerical) functions: y(x) and v(x). y(x) is the solution of the original second order ODE. v(x) is just y'(x) expressed as another function.

3. Apr 23, 2005

### eckiller

Thank you for your reply. Okay, up to this point I don't know what v(x) is in y'. I don't see how I can apply Runge-Kutta to y' = v(x) if I do not know v(x) !

4. Apr 23, 2005

### saltydog

v(x) is y'(x). Now, since you're using Runge-Kutta, you know the first data points right? You know y(a) and y'(a)=v(a). Runge-Kutta then calculates the second data points: y(deltax) and v(deltax), and so forth. You then end up with 2 functions. y(x) is the solution and v(x) is just . . . well extra.

5. Apr 23, 2005

### eckiller

Forgive me. This is probably something obviously simple I am missing.

y'(x) = v(x).

But I am not given what y' is. I am given y'' = f(t, y).

For example, to a numerical ODE solver, we supply the g function,

dy/dt = g(t, y),

as a parameter to the ODE solver. So I don't get what I am to supply because I don't know what v(x) is or dy/dt. Are you saying it is just:

y'(x) = v

where v is just linear? Almost as in y'(x) = t ? If so why not just integrate directly then?

6. Apr 23, 2005

### saltydog

Alright, I'm sorry you're having problems with my explanation. You know that for a second order ODE to have a "unique" solution, you MUST be give two conditions. Usually these are "initial conditions" in the form of y(0)=a and y'(0)=b. You need to have these values supplied in order to work the Runge-Kutta method. Your first post, as I interpreted it, indicated that you are given these two values.

I tell you what, even if you're not given them, try using just any values say y(0)=1 and y'(0)=0 or whatever and do the numeric analysis just to verify you have the algorithm down correctly.

You said:

"For example, to a numerical ODE solver, we supply the g function,

dy/dt = g(t, y)"

Well, even that you still need to supply an initial condition in the form (usually) of y(0)=a.

7. Apr 23, 2005

### eckiller

Yes I am given the initial conditions. But I still need the function. For simplicity, the Euler step:

slope = feval(funcHandle, t(i-1), y(i-1));
y(i) = y(i-1) + slope*step;

where funcHandle is the f(t, y) in y' = f(t, y).

8. Apr 23, 2005

### saltydog

I think I see the problem now: You need to calculate Runge-Kutta for BOTH y(x) AND v(x) simultaneously. You're given the starting points, then run through one delta x, calculate y(x) AND v(x) at that point, go to the next step, calculate both again, and so forth. It's a little messy.

9. Apr 23, 2005

### eckiller

Okay so going back to y'' = f(t, y)

Step each step:

(a) Solve v' = f(t, y) for this step
(b) Use solution from (a) to solve y' = v

Is that right?

10. Apr 23, 2005

### saltydog

Ok, so we have:

$$y^{'}=v(x)$$

$$v^{'}=f(x,y)$$

Calculate y(x1) and v(x1). You can do this because you have their derivatives there and the initial conditions y(0) and v(0). The next step, x2, you do that all over, calculate y(x2) AND v(x2) at the same time. You can do that since again, you know what the slopes are and what the previously calculated values were. Then do y(x3) AND v(x3) and so forth. You'll think it's easy once you do a few. Hope that helps. Gotta check out . . .

11. Apr 24, 2005

### eckiller

I see now. Thank you.