%*****************************************************************************80
%
%% newton_value_test tests newton_value.
%
fprintf ( 1, '\n' );
fprintf ( 1, 'newton_value_test:\n' );
fprintf ( 1, '  newton_value evaluates a polynomial in Newton form.\n' );
fprintf ( 1, '  This example evaluates such a polynomial that is an interpolant\n' );
fprintf ( 1, '  to the tangent function at -1.5, -0.75, 0, 0.75, 1.5.\n' );

c = [ 0.0, 4.83484, -10.8784, 17.5597, -14.1014 ];
z = [ -1.5, -0.75, 0, 0.75, 1.5 ];
tz = tan ( z );
nx = 33;
x = linspace ( -1.5, +1.5, nx );
tx = tan ( x );

px = newton_value ( c(end:-1:1), z, x );
for i = 1 : nx
  fprintf ( 1, '  %f  %f  %f\n', x(i), px(i), tx(i) );
end
clf ( );
hold ( 'on' );
plot ( x, px, 'r-', x, tx, 'b-' )
plot ( z, tz, 'k.', 'markersize', 20 );
hold ( 'off' );
grid ( 'on' );
xlabel ( '<-- x -->' );
ylabel ( '<-- f(x) -->' );
title ( 'Tan(x) and Quadric Polynomial interpolant' )
filename = 'newton_value_test.png';
print ( '-dpng', filename );
fprintf ( 1, '  Graphics saved as "%s"\n', filename );

