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

299 Views Asked by At

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.

1

There are 1 best solutions below

3
On BEST ANSWER

@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}.$$