# Solving initial value problem related to a given function using Euler's method

Solve the initial value problem related to $H(x,y) = x^2 + y^2 - 1 = 0$ and $(x_0,y_0) = (1,0)$, using the Euler method.

The problems I've seen on the internet always give the $y'$ in terms of $y$ and $x$ so what I did first was tro try to find this $y'$ since I don't know it yet.

By implicit differentiation I have that $y' = -x/y$

Now, If I set my $h=0.1$ for example, you can see on the first iteration I'll have an undefined value:

$x_0 = 1,y_0=0$

$x_1 = x_0 + h = 1.01,y_1 = y_0 + y'(x_0,y_0) = 0 + -1/0 \;\rightarrow UNDEFINED$

But I don't think this makes any sense, perhaps I differentiated incorrectly or this is just not the right way to go. I'd like someone to help me understand the very first step which is obtaining an ODE for a given function.

• Perhaps solve the Hamiltonian system $\dot y=H_x$, $\dot x=-H_y$. Jun 24, 2018 at 21:13
• @LutzL thank you for your comment, however I do not know what you mean by solving the Hamiltonian system, I haven't had that class yet. Jun 24, 2018 at 22:56
• I thought that was why the function was called $H$, for Hamiltionian. The way you related a differential equation to the level function does obviously not work, so you need to generate the vector field tangent to the curve in another way. Jun 25, 2018 at 11:41

@Lutz suggests another option, namely treat $x$ and $y$ as functions of the time $t$. From $$x(t)^2 + y(t)^2 = 1$$ we obtain by differentiation with respect to $t$ the equation $$2x(t)x'(t) + 2 y(t)y'(t) = 0.$$ This suggests to take $$\frac{d}{dt} \begin{bmatrix} x(t) \\ y(t) \end{bmatrix} = \begin{bmatrix} -y(t) \\ x(t) \end{bmatrix}.$$ This is a system of ordinary differential equations $$\mathbf{z}'(t) = \mathbf{f}(t,\mathbf{z}(t)),$$ where $$\mathbf{z}(t) = \begin{bmatrix} x(t) \\ y(t) \end{bmatrix}, \qquad \mathbf{f}\left(t,\begin{bmatrix} x \\ y \end{bmatrix}\right) = \begin{bmatrix} -y \\ x \end{bmatrix}.$$ The initial condition is $$\mathbb{z}_0 = \mathbf{z}(0) = \begin{bmatrix} x(0) \\ y(0) \end{bmatrix} =\begin{bmatrix} x_0 \\ y_0 \end{bmatrix} = \begin{bmatrix} 1\\ 0 \end{bmatrix}.$$ Euler's method takes the form $$\mathbf{z}_{n+1} = \mathbf{z}_n + h \mathbf{f}(t,\mathbf{z}_n)$$ or equivalently $$\begin{bmatrix} x_{n+1} \\ y_{n+1} \end{bmatrix} = \begin{bmatrix} x_n \\ y_n \end{bmatrix} + h \begin{bmatrix} -y_n \\ x_n \end{bmatrix} = \begin{bmatrix} x_n - hy_n \\ y_n + h x_n\end{bmatrix}.$$
• How would this work on the first iteration given that the sum I'll make is an scalar plus a vector ($0 + h\cdot[-y_0 \; x_0]^T$) ? Jun 25, 2018 at 15:12