% Euler's method for solving IVP
% y'(t) = f(t,y(t)), y(a) = alpha 
% t defined on [a,b]

f = @(t,y) (y - t.^2 + 1);

a = 0;
b = 2;
alpha = 0.5; % y(a) = alpha

h = 0.2;
N = (b-a)/h

t = [a:h:b];
w = zeros(N+1,1);

t(1) =a;

w(1) = alpha;

for i=2:N+1 %i=1:N
    w(i) = w(i-1) + h*f(t(i-1),w(i-1));
    t(i) = a+(i-1)*h;
    disp(['it # = ' num2str(i) ' %% ' 'w = ' num2str(w(i)) ] )
end
%format long g
disp('****************************************************')
disp(' t              w')
disp([num2str([t', w],8)])
disp('****************************************************')


