function val = hermite3(a,b,ya,yb,ypa,ypb,t)
%HERMITE3 Evaluate Hermite cubic interpolating polynomial
%
%       HERMITE3(a,b,ya,yb,ypa,ypb,t) returns the value(s) of the
%       Hermite cubic interpolating polynomial for the points a and b,
%       values ya and yb, and derivatives ypa and ypb, evaluated at t. t
%       may be a scalar, vector, or matrix, and the returned value is of
%       the same size and shape.
%
%       HERMITE3 uses the Newton form of the Hermite interpolating
%       polynomial.

% compute the divided differences to use as coefficients and
% evaluate the polynomial using nested evaluation.
d1=ya;
d4=ypb;
d3=(yb-ya)/(b-a);
d2=ypa;
d4=(d4-d3)/(b-a);
d3=(d3-d2)/(b-a);
d4=(d4-d3)/(b-a);
val = ((d4*(t-b)+d3).*(t-a)+d2).*(t-a)+d1;
