%
%  code02.m -- 15 sept 02 -- djm
%
%  - Euler's method example

clear;  clf

%  set t-points & initial y

t_init = -3
t_fin = 1
y_init = 3.4

N = input('input number of t-points on interval = ');
h = (t_fin-t_init)/N;

t = t_init:h:t_fin;
y(1) = y_init;

%  euler method iteration (note scalar arithmetic use * not .*, etc)

for j=1:size(t,2)-1
  y(j+1) = y(j) + ( t(j)^2 / (1-y(j)^2) )*h;
end

%  plot t_j versus v_j

plot(t,y,'bx')
title('\bf Euler''s method for page 41 (bad things happen at the corners)')
xlabel('t-axis')
ylabel('y(t)-axis')

disp(' ')
disp('experiment with changing the initial value')
