%
%  my second matlab script:  convergence study
%
%  save as: "hw00b.m"
%
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

%  set value of N (no colon displays command results!)

N = 50

disp(['the value of N = ' num2str(N)])

%  make a vector series from 0 to N

j0 = 0:1:N;
y  = zeros(size(j0));

y(1) = 0;
h    = pi/N;

%  execute a loop

for j=2:1:N+1
  y(j) = y(j-1) + h*(1 + y(j-1)^2)/4;
end

%  show the N+1th value (simple & fancy output)

format long
y(end)
format short

disp(' ')
disp(['the N+1th value of y = ' num2str(y(end),14)])
disp(' ')

%  make a plot (set to 0==1, if no plot!)

if (0==0)
   clf
   plot(j0,y,'r.')

%  label the plot

   title('plot of y_j-vector')
   xlabel('j-axis')
   ylabel('y_j-axis')
   axis([0 N 0 1])
   text(5,0.90,'this is a plot of the series y_j ...')
   text(15,0.80,['... from j = 0 to ' num2str(N)])
end
