#!/usr/bin/octave -q

% Jonathan Senning <jonathan.senning@gordon.edu>
% Gordon College
% January 1999
% Revised August 2000
% Revised April 27, 2006 to update graphing commands
% Revised December 19, 2008 to work with both Matlab and Octave
%
% This Octave program does essentially the same thing as the sequence
% of MatLab commands given on page 25 of "Numerical Mathematics and
% Computing", 4th edition, by Cheney and Kincaid, Brooks/Cole, 1999.

x = pi * [ -120 : 120 ]' / 100.0;
y1 = x;
y2 = x - (x.^3)/6.0;
y3 = x - (x.^3)/6.0 + (x.^5)/120.0;
y4 = sin( x );

plot( x, y1, x, y2, x, y3, x, y4 );
legend( 'y = T_1(x)', 'y = T_3(x)', 'y = T_5(x)', 'y = sin(x)' );
xlabel( 'x' );
ylabel( 'y' );
title( 'Partial sums of the Taylor series for sin(x)' );
drawnow();

yesno='';
yesno = input( 'Create PNG file? [y/N] ', 's' );

if ( length( yesno ) > 0 && ( yesno(1) == 'Y' || yesno(1) == 'y' ) )
  pngfile = 'sineplot.png';
  print( pngfile, '-dpng' );
  fprintf( 'PNG File %s was created\n', pngfile );
end

% End of File
