Matrices, vectors, and LinearSolve

myA = {{1, 2}, {2, 3}}

myA // MatrixForm

MatrixForm[myA]

g = {1, 4}

myA*g

myA . g

myA = {{a, b}, {c, d}}

LinearSolve[myA, {1, 0}]

myA . %

Natural cubic spline

Clear[f, xlist, ylist, n, h, a, g, myA, c, b, d, 
        plist];
f[x_] = Exp[-x^2];
xlist = {0. , 1. , 2. , 3. };
ylist = f[xlist];
n = Length[xlist];
h = 
        Table[xlist[[k + 1]] - xlist[[k]], {k, 1, 
            n - 1}];
a = ylist;
g = 
        Table[3/h[[k]] (a[[k + 1]] - a[[k]]) - 
            3/h[[k - 1]] (a[[k]] - a[[k - 1]]), {k, 2, 
            n - 1}];
g = Prepend[g, 0];
g = Append[g, 0];
myA = IdentityMatrix[n];
Do[
        myA = ReplacePart[myA, h[[k - 1]], {{k, k + 1}}], {k, 2, 
          n - 1}];
Do[
        myA = ReplacePart[myA, h[[k]], {{k, k - 1}}], {k, 2, 
          n - 1}];
Do[
        myA = ReplacePart[myA, 
            2 (h[[k - 1]] + h[[k]]), {{k, k}}], {k, 2, 
          n - 1}];
c = LinearSolve[myA, g];
b = 
        Table[(a[[k + 1]] - a[[k]])/h[[k]] - 
            h[[k]] (c[[k + 1]] + 2  c[[k]])/3, {k, 1, 
            n - 1}];
d = 
        Table[(c[[k + 1]] - c[[k]])/3/h[[k]], {k, 1, 
            n - 1}];
plist = 
        Table[a[[k]] + b[[k]] (x - xlist[[k]]) + 
            c[[k]] (x - xlist[[k]])^2 + 
            d[[k]] (x - xlist[[k]])^3, {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]

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

Show[fplot, plistplots]

plist // ColumnForm

My car

Clear[f, xlist, ylist, n, h, a, g, myA, c, b, d, 
        plist];
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}; 
    n = Length[xlist];
h = 
        Table[xlist[[k + 1]] - xlist[[k]], {k, 1, 
            n - 1}];
a = ylist;
g = 
        Table[3/h[[k]] (a[[k + 1]] - a[[k]]) - 
            3/h[[k - 1]] (a[[k]] - a[[k - 1]]), {k, 2, 
            n - 1}];
g = Prepend[g, 0];
g = Append[g, 0];
myA = IdentityMatrix[n];
Do[
        myA = ReplacePart[myA, h[[k - 1]], {{k, k + 1}}], {k, 2, 
          n - 1}];
Do[
        myA = ReplacePart[myA, h[[k]], {{k, k - 1}}], {k, 2, 
          n - 1}];
Do[
        myA = ReplacePart[myA, 
            2 (h[[k - 1]] + h[[k]]), {{k, k}}], {k, 2, 
          n - 1}];
c = LinearSolve[myA, g];
b = 
        Table[(a[[k + 1]] - a[[k]])/h[[k]] - 
            h[[k]] (c[[k + 1]] + 2  c[[k]])/3, {k, 1, 
            n - 1}];
d = 
        Table[(c[[k + 1]] - c[[k]])/3/h[[k]], {k, 1, 
            n - 1}];
plist = 
        Table[a[[k]] + b[[k]] (x - xlist[[k]]) + 
            c[[k]] (x - xlist[[k]])^2 + 
            d[[k]] (x - xlist[[k]])^3, {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[2*plistplots[[1]]]

Show[plistplots, AspectRatio -> Automatic]