clear;


%   demonstration of compound interest
a=1000;            %    initial capita
n=40;              %    number of years
int=8/100;         %    interest rate
t=a*(1+int)^n;     %    final dollars
t2=a*(1+n*int);    %    without compounding
int=int*100;       %    make it percent for printing
fprintf('return after %d years at %5.2f%% with    compounding  %10.2f \n',n,int,t);
fprintf('return after %d years at %5.2f%% without compounding  %10.2f \n',n,int,t2);
return


clear;
%..... demonstration of finite differences to 
%      calculate the derivative of sin(x)
dx=0.1;  i=0;
for x=0:dx:pi
    i=i+1;
    xx(i)=x;        %.... save for plotting
    %fprime(i) = (sin(x+dx)-sin(x))/dx;    %..... forward differences
    fprime(i) = (sin(x+dx)-sin(x-dx))/2/dx;  %  central differences, much more accurate
    yy(i)=cos(x);
    fprintf('  %20.10f   \n  %20.10f\n\n',fprime(i),yy(i));  %  print so numbers line up
end
i

  plot(xx,yy,xx,fprime);  %... plot together with exact values (cos(x))
  
  