# Difficult non-linear differential equation

1. Jun 20, 2012

### matteo86bo

1. The problem statement, all variables and given/known data

I need to solve this differential equation numerically. I hope you can help me, it's not homework!

2. Relevant equations

This is the equation to be solved

$x''=\dfrac{\alpha}{x}-\beta\dfrac{(x'-\gamma x)^2}{x}-\delta x - \dfrac{\varepsilon}{x^2}$

3. The attempt at a solution

I've tried with a simple discretization, but it doesn't seem to be stable.

$\dfrac{x(i)-2x(i-1)+x(i-2)}{h^2}=\dfrac{\alpha}{x(i-1)}-\beta\dfrac{\left(\dfrac{x(i)-x(i-1)}{h}-\gamma x(i-1)\right)^2}{x(i-1)}-\delta x(i-1) - \dfrac{\varepsilon}{x(i-1)^2}$

I think it's better to use Runge-Kutta IV but I have no idea how to apply it on such a complicated equation.

2. Jun 20, 2012

### Filip Larsen

You can reduce a second order ODE like that to a set of first order ODE by introducing an extra state variable. For instance, in your case you could set v = x' and get the following first order equations

v' = α/x - β (v-γx)2/x - δx - ε/x2, and
x' = v

Thus, (x,v) is the state of the system and the field that you have to provide to methods like RK4 is given by the right hand side of the equations.

3. Jun 20, 2012

### matteo86bo

Thanks that helped but I have still some problem in computing v.

According to what you wrote and the runge Kutta IV method definition the k should be:

$k1=hf(t_{i},x_{i})$
$k2=hf(t_{i+1/2},x_{i}+k1/2)$
$k3=hf(t_{i+1/2},x_{i}+k2/2)$
$k4=hf(t_{i+1},x_{i}+k3)$

How is v for every k?

4. Jun 20, 2012

### Filip Larsen

No, your state consist of two variables, not just one, meaning that in the context of the RK4 method the state variable (not to be confused with the x in your equations), the field f and the k-values are all two-dimensional. For instance, when applied to your state variables the stage k1 = h f(ti,yi) from the RK4 method (where I used y = (x,v) to denote the complete state) really means k1 = (kx1, kv1) = h f(ti,xi,vi).

5. Jun 20, 2012

### matteo86bo

Ah ok, thanks. So in my case, since I don't have an explicit time dependency the ks should be

$k1=hf(x_{i},v_{i})$
$k2=hf(x_{i}+k1/2,v_{i}+k1/2,)$
$k3=hf(x_{i}+k2/2,v_{i}+k2/2)$
$k4=hfx_{i}+k3,v_{i}+k3)$

Is that right?

6. Jun 20, 2012

### Filip Larsen

Correct, but remember as was mentioned, that the field f also evaluates to two values, one for x' and one for v' so you need to treat the k-values as vectors also when you combine them to a new y value.

7. Jun 20, 2012

### matteo86bo

Sorry but I don't understand how to compute the Ks considering them as arrays. I tried googling it but I couldn't find anything. Can please you make an example?

8. Jun 20, 2012

### Filip Larsen

You should treat them as vectors with two elements. If we define the field as the (column) vector

f(x,v) = ( fx(x,v), fv(x,v) )T ,

that is, a vector with the two elements

fx(x, v) = v and
fv(x, v) = α/x - β (v-γx)2/x - δx - ε/x2,

then from the definition of the RK4 method we have

k1 = h f(xi, vi) = ( h fx(xi,vi), h fv(xi,vi) )T

that is, the two elements of k1 is

h fx(xi, vi) and
h fv(xi, vi).

If you are still confused by this I suggest that you read up on vector algebra.

9. Jun 20, 2012

### matteo86bo

Ok, now I got it, thanks a lot for you time!