POLYFIT2 Polynomial approximation of a curve.


   usage :
   P = POLYFIT2(X, Y, N) finds the coefficients of a polynomial P(X) of
   degree N that fits the data, P(X(I))~=Y(I), in a least-squares sense.

   P = POLYFIT2(Y, N) use default equal spacing between all values of Y
   array.

   P = POLYFIT2(..., COND) specify end conditions for interpolated
   polynom. COND is [M*1] array of values, M(0) is value of interpolated
   polynom for X(1), M(2) is value of first derivative at first point, and
   so on for each derivative degree of X.
   If COND is [M*2] array, first column gives conditions for first point,
   and second column gives conditions for second point.
   
   P = POLYFIT2(..., COND1, COND2) 
   where COND1 and COND2 are column arrays, specify different end
   condition for each limit of the polynom domain.
   
   Example
   % defines a basis and a function to interpolate
   N = 50;                         % 50 points
   x = linspace(0, pi, N);         % basis range from 0 to PI
   y = cos(x)+randn(1,N)*.2;       % cosine plus gaussian noise
   figure; plot(x, y, '+');        % display result
   % Fit a degree 3 polynom, imposing to pass through end points [0 1] and
   % [PI -1]:
   p1 = polyfit2(x, y, 3, [1], [-1]);
   % Fit a degree 3 polynom, imposing to pass through end points [0 1] and
   % [PI -1], and imposing first derivative equals to zero at end points:
   p2 = polyfit2(x, y, 3, [1;0], [-1;0]);
   % display the different approximations
   hold on;
   plot(x, polyval(p1, x), 'g');
   plot(x, polyval(p2, x), 'r');


   See also  :
   polyfit (matlab)

Package: matgeom