# Thread: Numerically Solving a Second Order Nonlinear ODE

1. ## Numerically Solving a Second Order Nonlinear ODE

Hey guys, I am new here so hi.

Okay, I have this not so pretty 2nd order non-linear ODE I should be able to solve numerically.

f''(R)+(2/R)f'(R)=(.7/R)((1/sqrt(f))-((0.3)/sqrt(1-f))), f'(0)=1, f(1)=1

I was thinking of breaking this guy up into a system of two first order ODE's and then solve, but I have no idea how to set this up. What method should I use to set up the system of ODE's so I can solve them numerically? If there is some other way of solving this guy I am more than open to those methods.

2. The usual procedure is to let $\displaystyle f_{1}=f,$ and $\displaystyle f_{2}=f_{1}'.$ Then your DE would translate to the following system:

$\displaystyle f_{1}'=f_{2}$

$\displaystyle \displaystyle f_{2}'=-\frac{2f_{2}}{R}+\frac{.7}{R}\left(\frac{1}{\sqrt{ f_{1}}}-\frac{0.3}{\sqrt{1-f_{1}}}\right).$

Question: are the conditions $\displaystyle f'(0)=1, f(1)=1$ accurate? Because those are mixed boundary conditions, not initial conditions. That will radically change the method of solution. I would probably do some sort of shooting method (pick initial conditions, and try to "hit" the end conditions - keep doing until you get close enough).

If those conditions are accurate, you could try a combination of Runge-Kutta 4 with a shooting method.

Make sense?

3. Hey Ackbeet, the function f in terms of R and everything else is a constant (i.e. I have already put in the initial conditions). I am trying to replicate one of the solutions () with the constants 0.7 and 0.3.

From the picture I am pretty sure that the f(1)=1 boundary is okay. But I was not sure about the other one. From the looks of it f is approaching zero as R approaches zero from the positive side.

The Runge-Kutta 4 method should work anywhere between the asymptotic points. As for the asymptotes is there a method I can use to get as close as I can and still get a pretty good result.

4. The function f in terms of R and everything else is a constant (i.e. I have already put in the initial conditions).
That makes no sense. The function graphed in your attached png file is not constant. I'm assuming $\displaystyle \phi=f?$

From the looks of it f is approaching zero as R approaches zero from the positive side.
Not to me. It looks as though f is doing something wild near the origin. Is f the solid line plotted, or the dotted line?

Runge-Kutta 4 does NOT, by itself, solve boundary value problems like what you have here. It solves initial value problems. You can use Runge-Kutta 4 in conjunction with a higher-level algorithm, like a shooting method, to solve a boundary value problem.

5. The dotted line is the one I am focused on. Yea you are right, there could be some pretty wild behavior near origin they couldn't numerically solve (this graph is pretty old from 1967). From this I only know what the boundary conditions are at one end.

By focusing on only one of the solutions (one being the dotted line) am I not solving an initial value problem?

6. If you only know the "boundary conditions" at one end, then you really have initial conditions. It looks like the slope at R=1 is about 1. So you could have f(1) = 1, and f'(1) = 1. Those would be initial conditions. At this point, you could run RK4 backwards towards the origin. I would probably take smaller steps when you get to around 0.3, and 0.05. Corners are often numerically sensitive.

On second thought, your slope is less than one. You could try "shooting" towards the point (0.3,0), which is on a smooth part of the curve from (1,1). That might allow you to fine-tune the initial slope.

By focusing on only one of the solutions (one being the dotted line) am I not solving an initial value problem?
I wouldn't phrase it that way. Boundary versus initial conditions all has to do with the values of the independent variable at which you know something about the function. If you have a second-order DE, for example, and you know the function value and the first derivative at the same value, that's an initial value problem. On the other hand, if you know the function value at two different points, that's a boundary value problem.