# Euler method with infinite gradient at initial value

The title itself is self explanatory - I am trying to numerically solve an ODE with an initial value that has an infinite gradient. It seemed problematic to me and I am not certain as to how I should approach this.

e.g. $\frac {dy}{dx} = \frac y{\sqrt x} , y(0)=1$

(Obviously this can be solved analytically but I would like to know if there is any numerical method that tackles problems like this)

Thank you very much!

## 1 Answer

Others can probably give a more "conventional" approach but one thing you can do, because $y'(x)$ is independent of $y(x)$, is take the following approach for the first step (at least).

For the initial slope think rather angle. You want to proceed with a certain angle but you can't use $\theta_1=\frac{\pi}{2}$... which is obviously no good.

Instead take as angle the mid-angle of $\theta_1=\pi/2$ and the angle of the curve at $x=h$:

$$\theta_2:=\tan^{-1}\left(y'(h)\right)=\tan^{-1}\left(\frac{1}{\sqrt{h}}\right),$$

and so take as initial angle:

$$\theta_0=\frac{\theta_1+\theta_2}{2}=\frac{\frac{\pi}{2}+\tan^{-1}\left(\frac{1}{\sqrt{h}}\right)}{2},$$

and so an initial slope of:

$$m_0:=\tan(\theta_0).$$

From here you can do normal Euler or perhaps keep it going with slope

$$m_k=\frac{y'(x_k)+y'(x_{k+1})}{2}.$$

This is an adaptation of Heun's Method. With a step-size of $h=0.1$ this gives an error for $y_1\approx y(x_1)$ of the order of $0.015$.

• I should have make it clear that the ODE should be inhomogenous. Thank you for your answer though. – cssstudent Dec 12 '17 at 15:44
• @cssstudent perhaps perturb the initial condition to $y(\varepsilon)=1$? – JP McCarthy Dec 14 '17 at 14:38
• yes - that is perhaps the most simple way – cssstudent Dec 14 '17 at 18:54