% Ex. 2-4-30 in MatLab

% functions used f.m , euler1.m

% Main

[Xa,Ya] = euler1(0,2,0,20); % Make h=0.1 array

[Xb,Yb] = euler1(0,2,0,200); % Make h=0.01 array

[Xc,Yc] = euler1(0,2,0,2000); % Make h=0.001 array

% Plot  
plot(Xa,Ya,'k:',Xb,Yb,'k-.',Xc,Yc,'k-')
title('Graph of Ex. 2.4.30 - Approx. ')
legend('h=0.1','h=0.01','h=0.001','Location','NorthWest')

% Give user instructions
display(' ')
display('Use + zoom tool in graphics window to zoom in or out')

% Make tables 

% Make h=0.1 table
A = [Xa,Ya]; 
% display(' ') 
% display('For h=0.1:')
% [A(2,[1 2]) ; A(6,[1 2]) ; A(11,[1 2]) ; A(16,[1 2]) ; A(21,[1 2]) ]

% Make h=0.01 table
B = [Xb,Yb]; 
% display(' ')
% display('For h=0.01:')
% [B(11,[1 2]) ; B(51,[1 2]) ; B(101,[1 2]) ; B(151,[1 2]) ; B(201,[1 2]) ]

% Make h=0.001 table
C = [Xc,Yc]; 
% display(' ')
% display('For h=0.001:')
% [C(101,[1 2]) ; C(501,[1 2]) ; C(1001,[1 2]) ; C(1501,[1 2]) ; C(2001,[1 2]) ]

% display combined table
display(' ')
display('Combined table for x, h=0.1, h=0.01, h=0.001:')

[A(2,[1 2]) B(11,[2]) C(101,[2]) ; A(6,[1 2]) B(51,[2]) C(501,[2]) ; 
    A(11,[1 2]) B(101,[2]) C(1001,[2]) ; A(16,[1 2]) B(151,[2]) C(1501,[2]) ;
    A(21,[1 2]) B(201,[2]) C(2001,[2]) ]

display(' ')
display('To look at data - ')
display('Type [Xa,Ya] to see data for h=0.1')
display('Type [Xb,Yb] to see data for h=0.01')
display('Type [Xc,Yc] to see data for h=0.001.') 
display(' ')

