# Math Help - Euler's method

1. ## Euler's method

The question goes...

Implement Euler's method in order to find a numerical solution of the equation

$y'=y^2-2xy+1+x^2$ which satisfies $y(0)=-1$

integrate over the domain $0\leq x\leq 5$, choosing suffiecently small step length.

Then I've gotta plot a graph on this program, which I'll be able to do if I had a clue how to do the question can anyone help?

2. Originally Posted by chella182
The question goes...

Implement Euler's method in order to find a numerical solution of the equation

$y'=y^2-2xy+1+x^2$ which satisfies $y(0)=-1$

integrate over the domain $0\leq x\leq 5$, choosing suffiecently small step length.

Then I've gotta plot a graph on this program, which I'll be able to do if I had a clue how to do the question can anyone help?
Haha. You must do Maths at Newcastle, aye?

The same as Matt.

I had to help him with it too :P.

Euler's method says that, given a step size h, and a differential equation $y' = f(x,y)$ then the solution to a differential equation is given by:

$y_{k+1} = y_k + h \times \big(f(x_k,y_k)\big)$

And that

$x_{k+1} = x_k + h$

So for you, your equations would be:

$y_{k+1} = y_k + h \times \big(y^2 - 2xy + x^2+1\big)$

$x_{k+1} = x_k + h$

So your program should look something like this:

Code:
set x(1) = 0
set y(1) = -1
set h = 0.01

for k = 2 to 501 in steps of 1
y(k) = y(k-1)+h*((y(k-1))^2-2*(x(k-1))*(y(k-1))+1+(x(k-1))^2);
x(k) = x(k-1)+h;
end

plot(x,y)
Of course, I'm fairly sure you guys use maple, whereas I am more conversant in MatLab, so I can't give the program to you in Maple!

However, in matlab, it looks like this:

Code:
x(1) = 0;
y(1) = -1;
h= 0.01;

for i = 2:1:501;
y(i) = y(i-1)+h*((y(i-1))^2-2*(x(i-1))*(y(i-1))+1+(x(i-1))^2);
x(i) = x(i-1)+h;
end

plot(x,y,'r')
If I'm talking out of context here, you may be better to talk to Matt. He uses this forum, goes by the name Mitch something! He'll know.

3. I do indeed & I know Matthew

I don't remember doing Euler's method at all this semester so it confused me when it came up. Thanks though