reset();

x := [0, 1, 2, 3, 4];
y := map(x,x->f(x));

[0, 1, 2, 3, 4]
[f(0), f(1), f(2), f(3), f(4)]

S1:=numeric::cubicSpline(x,y,Natural,Symbolic);

`proc S1(z) ... end`

S1e:=piecewise([t>=0 and t<1, S1(t,0)],[t<2, S1(t,1)], [t<3, S1(t,2)], [Otherwise, S1(t,3)]);

piecewise([t < 2, f(1) - (t - 1)*((13*f(0))/28 + (3*f(1))/14 - (6*f(2))/7 + (3*f(3))/14 - f(4)/28 - (t - 1)*((45*f(0))/56 - (51*f(1))/28 + (9*f(2))/7 - (9*f(3))/28 + (3*f(4))/56 - (t - 1)*((19*f(0))/56 - (29*f(1))/28 + (8*f(2))/7 - (15*f(3))/28 + (5*f(4))/56)))], [t < 3, f(2) - (t - 2)*((3*f(1))/4 - f(0)/8 - (3*f(3))/4 + f(4)/8 + (t - 2)*((3*f(0))/14 - (9*f(1))/7 + (15*f(2))/7 - (9*f(3))/7 + (3*f(4))/14 - (t - 2)*((5*f(0))/56 - (15*f(1))/28 + (8*f(2))/7 - (29*f(3))/28 + (19*f(4))/56)))], [t in Dom::Interval([0], 1), f(0) - t*(((17*f(1))/28 - (15*f(0))/56 - (3*f(2))/7 + (3*f(3))/28 - f(4)/56)*t^2 + (71*f(0))/56 - (45*f(1))/28 + (3*f(2))/7 - (3*f(3))/28 + f(4)/56)], [Otherwise, f(3) + (t - 3)*((3*f(1))/14 - f(0)/28 - (6*f(2))/7 + (3*f(3))/14 + (13*f(4))/28 + (t - 3)*((3*f(0))/56 - (9*f(1))/28 + (9*f(2))/7 - (51*f(3))/28 + (45*f(4))/56 - (t - 3)*(f(0)/56 - (3*f(1))/28 + (3*f(2))/7 - (17*f(3))/28 + (15*f(4))/56)))])

S2:=numeric::cubicSpline(x,y,Complete=[f'(0),f'(4)],Symbolic);

`proc S2(z) ... end`

S2e:=piecewise([t>=0 and t<1, S2(t,0)],[t<2, S2(t,1)], [t<3, S2(t,2)], [Otherwise, S2(t,3)]);

piecewise([t < 2, f(1) - (t - 1)*((45*f(0))/56 - (3*f(1))/14 - (3*f(2))/4 + (3*f(3))/14 - (3*f(4))/56 + (15*D(f)(0))/56 + D(f)(4)/56 - (t - 1)*((39*f(0))/28 - (18*f(1))/7 + (3*f(2))/2 - (3*f(3))/7 + (3*f(4))/28 + (13*D(f)(0))/28 - D(f)(4)/28 - (t - 1)*((11*D(f)(0))/56 + (33*f(0))/56 - (3*D(f)(4))/56 + (9*f(4))/56 - (19*f(1))/14 + (5*f(2))/4 - (9*f(3))/14)))], [t < 3, f(2) + (t - 2)*((3*f(0))/14 - (6*f(1))/7 + (6*f(3))/7 - (3*f(4))/14 + D(f)(0)/14 + D(f)(4)/14 - (t - 2)*((3*f(0))/8 - (3*f(1))/2 + (9*f(2))/4 - (3*f(3))/2 + (3*f(4))/8 + D(f)(0)/8 - D(f)(4)/8 - (t - 2)*((3*D(f)(0))/56 + (9*f(0))/56 - (11*D(f)(4))/56 + (33*f(4))/56 - (9*f(1))/14 + (5*f(2))/4 - (19*f(3))/14)))], [t in Dom::Interval([0], 1), f(0) + t*(D(f)(0) - t*((123*f(0))/56 - (39*f(1))/14 + (3*f(2))/4 - (3*f(3))/14 + (3*f(4))/56 + (97*D(f)(0))/56 - D(f)(4)/56 - t*((41*D(f)(0))/56 + (67*f(0))/56 - D(f)(4)/56 + (3*f(4))/56 - (25*f(1))/14 + (3*f(2))/4 - (3*f(3))/14)))], [Otherwise, f(3) - (t - 3)*((3*f(0))/56 - (3*f(1))/14 + (3*f(2))/4 + (3*f(3))/14 - (45*f(4))/56 + D(f)(0)/56 + (15*D(f)(4))/56 - (t - 3)*((3*f(0))/28 - (3*f(1))/7 + (3*f(2))/2 - (18*f(3))/7 + (39*f(4))/28 + D(f)(0)/28 - (13*D(f)(4))/28 - (t - 3)*(D(f)(0)/56 + (3*f(0))/56 - (41*D(f)(4))/56 + (67*f(4))/56 - (3*f(1))/14 + (3*f(2))/4 - (25*f(3))/14)))])

S3:=numeric::cubicSpline(x,y,NotAKnot,Symbolic);

`proc S3(z) ... end`

S3e:=piecewise([t>=0 and t<1, S3(t,0)],[t<2, S3(t,1)], [t<3, S3(t,2)], [Otherwise, S3(t,3)]);

piecewise([t < 2, f(1) - (t - 1)*((7*f(0))/24 + (2*f(1))/3 - (5*f(2))/4 + f(3)/3 - f(4)/24 - (t - 1)*(f(0)/2 - f(1) + f(2)/2 - (t - 1)*((5*f(0))/24 - (2*f(1))/3 + (3*f(2))/4 - f(3)/3 + f(4)/24)))], [t < 3, f(2) - (t - 2)*((2*f(1))/3 - f(0)/12 - (2*f(3))/3 + f(4)/12 + (t - 2)*(f(0)/8 - f(1) + (7*f(2))/4 - f(3) + f(4)/8 - (t - 2)*(f(0)/24 - f(1)/3 + (3*f(2))/4 - (2*f(3))/3 + (5*f(4))/24)))], [t in Dom::Interval([0], 1), f(0) - t*((23*f(0))/12 - (10*f(1))/3 + 2*f(2) - (2*f(3))/3 + f(4)/12 - t*((9*f(0))/8 - 3*f(1) + (11*f(2))/4 - f(3) + f(4)/8 - t*((5*f(0))/24 - (2*f(1))/3 + (3*f(2))/4 - f(3)/3 + f(4)/24)))], [Otherwise, f(3) + (t - 3)*(f(1)/3 - f(0)/24 - (5*f(2))/4 + (2*f(3))/3 + (7*f(4))/24 + (t - 3)*(f(2)/2 - f(3) + f(4)/2 + (t - 3)*(f(0)/24 - f(1)/3 + (3*f(2))/4 - (2*f(3))/3 + (5*f(4))/24)))])

S4:=numeric::cubicSpline([op(x),x[1]],[op(y),y[1]],Periodic,Symbolic);

`proc S4(z) ... end`

S4e:=piecewise([t>=0 and t<1, S4(t,0)],[t<2, S4(t,1)], [t<3, S4(t,2)], [Otherwise, S4(t,3)]);

piecewise([t < 2, f(1) - (t - 1)*((17*f(0))/48 + (5*f(1))/12 - (7*f(2))/8 + f(3)/12 + f(4)/48 - (t - 1)*((5*f(0))/8 - (3*f(1))/2 + (5*f(2))/4 - f(3)/2 + f(4)/8 - (t - 1)*((13*f(0))/48 - (11*f(1))/12 + (9*f(2))/8 - (7*f(3))/12 + (5*f(4))/48)))], [t < 3, f(2) - (t - 2)*((2*f(1))/3 - f(0)/12 - (2*f(3))/3 + f(4)/12 + (t - 2)*((3*f(0))/16 - (5*f(1))/4 + (17*f(2))/8 - (5*f(3))/4 + (3*f(4))/16 - (t - 2)*((5*f(0))/48 - (7*f(1))/12 + (9*f(2))/8 - (11*f(3))/12 + (13*f(4))/48)))], [t in Dom::Interval([0], 1), f(0) - t*((5*f(0))/3 - (7*f(1))/3 + f(2)/2 + f(3)/3 - f(4)/6 - t*((11*f(0))/16 - (5*f(1))/4 + f(2)/8 + (3*f(3))/4 - (5*f(4))/16 - t*(f(0)/48 + f(1)/12 - (3*f(2))/8 + (5*f(3))/12 - (7*f(4))/48)))], [Otherwise, f(3) + (t - 3)*(f(0)/48 + f(1)/12 - (7*f(2))/8 + (5*f(3))/12 + (17*f(4))/48 + (t - 3)*(f(0)/8 - f(1)/2 + (5*f(2))/4 - (3*f(3))/2 + (5*f(4))/8 + (t - 3)*((5*f(1))/12 - (7*f(0))/48 - (3*f(2))/8 + f(3)/12 + f(4)/48)))])

 

f:=x->(x+1)/(x^2+1);

x -> (x + 1)/(x^2 + 1)

plot(
  plot::Function2d(S1(t), t=0..4, Color = RGB::Black,Legend="Natural"),
  plot::Function2d(S2(t), t=0..4, Color = RGB::Red,Legend="Complete"),
  plot::Function2d(S3(t), t=0..4, Color = RGB::Blue,Legend="Not a Knot"),
  plot::Function2d(S4(t), t=0..4, Color = RGB::Orange,Legend="periodic"),
  plot::Function2d(f(t), t=0..4, Color = RGB::Green,Legend="f")
);

MuPAD graphics