Piecewise Hermite interpolation example

Clear[f, x, p, xlist, ylist, l, dl];
f[x_] = Exp[-x^2];
xlist = {0. , 0.5, 1. , 1.5, 2};
ylist = f[xlist];
dylist = f'[xlist];
n = Length[xlist];
plist = 
      Table[
x0 = xlist[[k]]; 
x1 = 
          xlist[[k + 1]]; 
y0 = 
          ylist[[k]]; 
y1 = 
          ylist[[k + 1]]; 
dy0 = 
          dylist[[k]]; 
dy1 = 
          dylist[[k + 
                1]]; 
l = {(x - x1)/(x0 - 
                  x1), (x - x0)/(x1 - 
                  x0)}; 
h = {(1 - 
                  2 (x - x0)/(x0 - x1)) ((x - x1)/(x0 - 
                        x1))^2, (1 - 
                  2 (x - x1)/(x1 - x0)) ((x - x0)/(x1 - 
                        x0))^2}; 
hhat = {(x - 
                  x0) ((x - x1)/(x0 - x1))^2, (x - 
                  x1) ((x - x0)/(x1 - 
                        x0))^2}; 
y0*h[[1]] + 
          y1*h[[2]] + dy0*hhat[[1]] + 
          dy1*hhat[[2]]
, {k, 1, n - 1}]

Collect[plist, x]

plistplots = 
      Table[Plot[plist[[k]], {x, xlist[[k]], xlist[[k + 1]]}, 
          PlotStyle -> {Hue[k/n - 1], AbsoluteThickness[2]}], {k, 1, 
          n - 1}]

fplot = 
      Plot[f[x], {x, xlist[[1]], xlist[[n]]}, 
        PlotStyle -> {GrayLevel[0.5], AbsoluteThickness[2]}]

Show[fplot, plistplots]

Show[plistplots]

Piecewise Hermite interpolation for data

xlist = Range[0, 18];
ylist = {0.0, 0.7, 1.2, 1.3, 1.45, 1.55, 1.9, 2.35, 2.65, 2.75, 2.9, 
          2.9, 2.9, 2.5, 2.0, 1.65, 1.55, 1.9, 2.2};

dylist = 
        Table[(ylist[[k + 1]] - ylist[[k - 1]])/2, {k, 2, 
            Length[ylist] - 1}];

dylist = Prepend[dylist, 0.5]

dylist = Append[dylist, 0. ]

Length[dylist]

Clear[f, x, p, l, h, hhat];
n = Length[xlist];
plist = 
        Table[
x0 = xlist[[k]]; 
x1 = 
            xlist[[k + 1]]; 
y0 = 
            ylist[[k]]; 
y1 = 
            ylist[[k + 1]]; 
dy0 = 
            dylist[[k]]; 
dy1 = 
            dylist[[k + 
                  1]]; 
l = {(x - x1)/(x0 - 
                    x1), (x - x0)/(x1 - 
                    x0)}; 
h = {(1 - 
                    2 (x - x0)/(x0 - x1)) ((x - x1)/(x0 - 
                          x1))^2, (1 - 
                    2 (x - x1)/(x1 - x0)) ((x - x0)/(x1 - 
                          x0))^2}; 
hhat = {(x - 
                    x0) ((x - x1)/(x0 - x1))^2, (x - 
                    x1) ((x - x0)/(x1 - 
                          x0))^2}; 
y0*h[[1]] + 
            y1*h[[2]] + dy0*hhat[[1]] + 
            dy1*hhat[[2]]
, {k, 1, 
            n - 1}];

plistplots = 
      Table[Plot[plist[[k]], {x, xlist[[k]], xlist[[k + 1]]}, 
          PlotStyle -> {Hue[k/n - 1], AbsoluteThickness[2]}], {k, 1, 
          n - 1}]

Show[plistplots, AspectRatio -> Automatic]