function QVals = pwQEval(a,x,zVals)

% QVals = pwLEval(a,x,zvals)

% Evaluates the piecewise quadratic polynomial defined by the column

% 3(n-1) vector a and the column n-vector x. It is assumed that x(1) < ... < x(n).

% zVals is a column m-vector with each component in [x(1),x(n)].

%

% LVals is a column m-vector with the property that LVals(j) = Q(zVals(j))

% for j=1:m where Q(z)= a(3*(i-1)+1) + a(3*(i-1)+2)(z-x(i)) + a(3*(i-1)+3)*(z-x(i))*(z-x(i+1)) for x(i)<=z<=x(i+1).

m = length(zVals);

QVals = zeros(m,1);

g = 1;

for j=1:m

i = Locate(x,zVals(j),g);

z = zVals(j);

QVals(j) = a(3*(i-1)+1) + a(3*(i-1)+2)*(z-x(i)) + a(3*(i-1)+3)*(z-x(i))*(z-x(i+1));

g = i;

end