function P = polyfitbyed(x,y,n)
% POLYFITBYED  Re-implementation by Ed of the built-in polyfit.
%     This version is more limited than built-in polyfit because
%     only the  degree = (number of points - 1)  case is covered.
%
% Example of comparison:
%   >> x = [1 2 5 6]
%   >> polyfit(x,sin(x),3)
%   >> polyfitbyed(x,sin(x),3)
%
% See also: POLYVALBYED

if length(x) ~= (n+1), error('number of points must be n+1'), end
if length(y) ~= (n+1), error('number of points must be n+1'), end
y = y(:);      % makes y into a column vector
A = vander(x);
P = (A \ y)';
