% OrthogPolyRegrP: Produces plot for orthogonal polynomial regression.
%
%     Usage: [xp,yp] = orthogpolyregrp(x,b,P,alpha,beta)
%
%         x =     column vector of unique independent-variable values.
%         b =     column vector of regression coefficients.
%         P =     values of observations (rows) for each orthogonal polynomial 
%                   term (cols).
%         alpha = alpha coefficients used to calculate polynomials.
%         beta =  beta coefficients used to calculate polynomials.
%         --------------------------------------------------------------------
%         xp,yp = predicted coordinates for plotting.
%

% RE Strauss, 2/14/02

function [xp,yp] = orthogpolyregrp(x,b,alpha,beta)
  xp = linspace(min(x),max(x))';
  k = length(xp);
  degree = length(b)-1;
  P = zeros(k,degree+1);

  P(:,1) = ones(k,1);                 % Term 0
  P(:,2) = (xp-alpha(2)).*P(:,1);     % Term 1

  for term = 2:degree                 % Remaining terms
    j = term+1;
    P(:,j) = (xp-alpha(j)).*P(:,j-1) - beta(j-1)*P(:,j-2);
  end;
  
  yp = P*b;                           % Predicted values at x's

  return;
  
