# Finite difference for 2nd order ode $y'^2+y y''+\frac{2}{x} y y' -0.1 y^2=0$ with $y'(1)=0$ and $y(1)=1$

How to solve second order non-linear ODE $$y'^2+y y''+\frac{2}{x} y y' -0.1 y^2=0$$ subject to $y'(1)=0$ and $y(1)=1$ over the interval $0 < x \le 1$.

I turned the equation to a PDE $y'^2+y y''+\frac{2}{x} y y' -0.1 y^2=y'_t$. I was trying to find the steady state solution when $t \to \infty$, which is the solution to the ODE. I used an explicit finite difference scheme in MATLAB. But it doesn't seem to give the right solution.

I have problem implementing boundary conditions in the MATLAB.

I will be grateful if you help me solve this. Also mentioning any other numerical method will be great. Thanks.

• Cross-posting is discouraged on the StackExchange network, so people don't waste their time with an answer you already received on the other site. The usual procedure is to wait a few days, and then either raise a flag and ask the moderators for migration (if there are some answers already) or delete the old and ask a new question. math.stackexchange – Mauro Vanzetto Jan 29 '18 at 16:28
• This is an initial value problem, so why are you not just using Matlab's built-in ODE solvers like ode45? – Kirill Jan 29 '18 at 18:37

You have two conditions at x=1, I hope this is correct in which case you have an initial value problem. If yes, then you can write this as a first order system by introducing $z=y'$

$$z' = y/10 - z^2/y - 2z/x, \qquad y' = z$$ with initial condition $$y(1) = 1, \qquad z(1) = 0$$ Solve this using an ode solver from $x=1$ to $x=0$. As you approach $x=0$, you will face the problem of division by zero, unless $z \to 0$. There is also possibility of $y$ becoming zero. Do you have a reason to expect your equation should have non-negative solutions ?

• I have doubt about boundary conditions. I wanted to see if the conditions are reasonable or not. I solved this analytically using MATHEMATICA. It gives: $$y=(1+i)\exp\left(\frac{1}{10}\left(-5\log(x)+5\log\left(\cosh\left(x/\sqrt{5}+0.2\left(\sqrt{5}+5\text{arctanh}\left(\sqrt{5}\right)\right)\right)\right)\right)\right)$$ which has a very small imaginary part and goes to $+ \infty$ at $x \to 0$. From this complex number I doubt that my friend has given me the wrong boundary conditions! – Ghartal Jan 29 '18 at 12:19

Sometimes, pdes result in solutions that are not steady (flow around a cylinder) and therefore you face a problem in which infinitely many solutions arise. This kind of problems are not suitable for temporal discretisations if one particular solution must be reached. I mean the limit $$\lim_{t\to \infty}y(t)$$ does not make any sense.

Instead you can linearise the problem (Newton's method) by setting: $$y^{n+1}=y^n+\delta y^n$$ And solve for $\delta y^n$ from linear problems carrying a substitution into your nonlinear model. Apply homogeneous dirichlet BC.

Keep in mind that nonlinear terms in $\delta y^n$ can be neglected because it is supposed small.

If the funcion $y$ is smooth enough near the possible solutions Newton's method will do the job with quadratic convergence.

• Thanks. Newton will do it. I have problems writing the Matlab code. Thank you again. – Ghartal Jan 29 '18 at 12:12