# Euler method classification

Consider the IVP $$y' = \frac{1}{t^2} - \frac{y}{t} = y^2$$ with $t$ an element of $[1,2]$ and $y(1) = -1$. The exact solution is $y(t) = -1/t$

(a) How can we use Euler's method with $h = 0.05$ to approximate the solution & and compare it to actual values of $y$?

(b) Use answer in part (a), and linear interpolation to approx the following values of $y$ and compare also with actual values:

$y(1.052)$

$y(1.555)$

$y(1.978)$

I'm stuck at the euler setup in part (a), and also, with the portion of comparing errors. Can you work out for one of the values in part (b), so I can get it?

-

Here is some pseudo code for (a):

h := 0.05;
// The number of xs minus 1 is the number of steps you'll do:
number_of_xs := length([1: h : 2]) - 1;

y_Euler(0) := -1; // Initialise your array of ys.
for i = 0 to i = (number_of_xs-1) do
y_Euler(i+1) = y_Euler(i) + h*y_Euler(i)^2;

// Then you want to compute the exact values:
xs := [1: h : 2];
y_exact := -1/xs; // Alternatively, write a for loop.

// Then you want to compute the (local) error:
err := abs(y_Euler - y_exact);


You might want to read about local and global error in the second paragraph here. Hope this helps.

-
Any ideas on how I can do this on Maple? –  user87274 Oct 31 '13 at 19:52