function [y, y1] = newtonfun(x)

% Example function for use with the 
% Newton's Method demonstration.

global p;
p = -5 + 10*rand(5, 1);

y = p(1) + ...
      p(2)*cos((2*pi/10)*x) + ...
      p(3)*sin((2*pi/10)*x) + ...
      p(4)*cos((4*pi/10)*x) + ...
      p(5)*sin((4*pi/10)*x);

y1 = -p(2)*(2*pi/10)*sin((2*pi/10)*x) + ...
         p(3)*(2*pi/10)*cos((2*pi/10)*x) - ...
         p(4)*(4*pi/10)*sin((4*pi/10)*x) + ...
         p(5)*(4*pi/10)*cos((4*pi/10)*x);