function pval = dPOLYVAL(deg,coeff,Z,R,jvec,dbox)

%--------------------------------------------------------------------------
% Object:
% This routine evaluates the weighted-regression polynomial of degree 
% "deg", defined through its coefficient vector "coeff", at the d-dim 
% target points "Z".
%--------------------------------------------------------------------------
% Input:
% deg: polynomial degree
% coeff: 1-column array of of weighted-regression coefficients;
% Z: d-column array of target point coordinates;
% R: invertible triangular factor provided by dPOLYFIT;
% jvec: vector of column indices, selects a polynomial basis;
% dbox: d-dim box where to adapt the product Chebyshev basis.
%--------------------------------------------------------------------------
% Output;
% pval: evaluation of the weighted-regression polynomial at the target 
%    points
%--------------------------------------------------------------------------
% Dates:
% Written by M. Dessole, F. Marcuzzi, M. Vianello - July 2020
%
% Modified by M. Dessole, A. Sommariva, M. Vianello - November 2020
%--------------------------------------------------------------------------

% .........................  Function Body ................................

% ..... troubleshooting .....

if nargin < 6, dbox=[]; end
if nargin < 5, jvec=[]; end


% ..... main code below .....

V = dCHEBVAND(deg,Z,dbox);
pval = (V(:,jvec)/R)*coeff;



