%This is a script file to test the yprimeO2 routine.
%
%It erases any file (in the Matlab path) called prog4run.txt, and
%writes output to a file in the Matlab working directory called prog3run.
%
%Your MeanAbsErr should be less than h^2 until h gets so small that rounding
%errors dominate (this begins to appear in this experiment at h=10^(-6))
%

%if exist('prog4run.txt','file'),
warning('OFF','all')
if exist('prog4run.txt') == 2,
    delete('prog4run.txt')
	disp(' ')
	disp('deleting old prog4run.txt file to make new one')
end
warning('ON','all')
cf = get(0,'Format');
format short e
diary prog4run.txt

h = 1e-1
x = -pi:h:pi;  y = sin(x);
yp = yprimeO2(y,x);
MeanAbsErr = sum(abs(yp(:)'-cos(x)))/length(x)
disp(' ')

h = 1e-3
x = -pi:h:pi;  y = sin(x);
yp = yprimeO2(y,x);
MeanErr = sum(abs(yp(:)'-cos(x)))/length(x)
disp(' ')

h = 1e-6
x = -1e-1*pi:h:1e-1*pi;  y = sin(x);
yp = yprimeO2(y,x);
MeanAbsErr = sum(abs(yp(:)'-cos(x)))/length(x)
disp(' ')

h = 1e-9
x = -1e-5*pi:h:1e-5*pi;  y = sin(x);
yp = yprimeO2(y,x);
MeanAbsErr = sum(abs(yp(:)'-cos(x)))/length(x)
disp(' ')

h = 1e-12
x = -1e-7*pi:h:1e-7*pi;  y = sin(x);
yp = yprimeO2(y,x);
MeanAbsErr = sum(abs(yp(:)'-cos(x)))/length(x)

%h = 1e-3, x = -pi:h:pi;  y = sin(x); yp = yprimeO2(y,x); MeanAbsErr = sum(abs(yp-cos(x)))/length(x),plot(x,yp-cos(x)),title('numdiff(sin(x)) - cos(x)')


diary off
format(cf);
