% FILE hlp116.m begins.
function dy = numder(y,h)
%NUMDER gives numerical approximation of derivative
%	of equally spaced data y = y(x+j*h), j=1,...,m, m >=5.
%	The 5-point rule numerical differentiation coefficients, 
%	from Abramowitz-Stegun 25.3.6 are used.  To compute 
%       dy0=f'(x0) at a single point x0 set e.g. h =0.001
%       x=x0-2*h:h:x0+2*h; y = f(x); dy=numder(y,h); dy0=dy(3);  
coe=[];
for p =-2:2
a= (2*p^3-3*p^2-p+1)/12;     b= (4*p^3-3*p^2-8*p+4)/6;
c= (2*p^3-5*p)/2;
d= (4*p^3+3*p^2-8*p-4)/6;    e= (2*p^3+3*p^2-p-1)/12;
coe=[coe; [a -b c -d e]];
end;
[d1,d2]=size(y);
if ((min(d1,d2)>1) | (max(d1,d2) <5))
  error('Argument error in numder');
end;
dy =y;
dy(1)=(1/h)*sum(coe(1,:).*y(1:5));
dy(2)=(1/h)*sum(coe(2,:).*y(1:5));
for p=3:d2-2
   dy(p)=(1/h)*sum(coe(3,:).*y(p-2:p+2));
end;
dy(d2-1)=(1/h)*sum(coe(4,:).*y(d2-4:d2));
dy(d2)=(1/h)*sum(coe(5,:).*y(d2-4:d2));
%  numder.m ends.

function y = pic(fexpr)
% PIC plots the graphs of functions: MATLAB 5.3 (R11)
% USAGE: pic(fexpr) where fexpr is a MATLAB function expression
% Example: pic('sin(tan(x)) ')
% N.B. The argument name must be x.
% SAVES data in pic.dat
clf;
disp([' Enter now argument bounds x1, x2 for ' fexpr]);
t ='Please enter'; x1=input([ t ' x1: ']);
x2=input([ t ' x2: ']); x =x1: (x2-x1)/100: x2;
% N.B. x is a global variable name "sin(x)"
eval(['f = ' fexpr ';']);
axes('FontSize',[15],'FontWeight','bold'); hold on;
fig=plot(x,f); grid
title(['    y =  ' fexpr],'FontSize',[15],'FontWeight','bold');
xlabel('PIC.M','FontSize',[15],'FontWeight','bold');
delete pic.dat;            diary pic.dat;
disp(['f = ' fexpr]);
disp( ['     x       f     '] );
disp(['--------------------']);
disp([x' , f']);   diary off;
set(fig,'LineWidth',2.5);
y ='pic.m completed and data saved in pic.dat';
% pic.m  ends.
% FILE hlp116.m ends.