MS-C1650 - Numeerinen analyysi
Lecture 4: Piecewise Interpolation

Harri Hakula, 2019

Hermite or something like it

x=.

Let us interpolate the function f(x) = 3(x^4)-2(x^2)+Sin[x]+1 over the interval x∈[-1,1].

Plot[3(x^4)-2(x^2)+Sin[x]+1,{x,-1,1}]

Choose points and find the values and the derivatives.

fun=Function[x,3(x^4)-2(x^2)+Sin[x]+1];
Dfun=Function[x,Evaluate[D[fun[x],x]]];
DDfun=Function[x,Evaluate[D[fun[x],{x,2}]]];

x=Subdivide[-1,1,6]

y=fun/@x

dy=Dfun/@x

if=Interpolation[N@Transpose[{x,y}],Method->"Hermite"];

Plot[{fun[x],if[x]},{x,-1,1}]

if/@x
N[fun/@x]
Function[ξ,Evaluate[D[if[ξ],ξ]]]/@x
N[Dfun/@x]

Function[ξ,Evaluate[D[if[ξ],{ξ,2}]]]/@x
N[DDfun/@x]

Hermite or something like it

Let us add the derivatives at points.

if=Interpolation[N@MapThread[{{#1},#2,#3}&,{x,y,dy}],Method->"Hermite"];

if/@x
N[fun/@x]
Function[ξ,Evaluate[D[if[ξ],ξ]]]/@x
N[Dfun/@x]

Function[ξ,Evaluate[D[if[ξ],{ξ,2}]]]/@x
N[DDfun/@x]

Spline or something like it

is=Interpolation[N@Transpose[{x,y}],Method->"Spline"];

Plot[{fun[x],if[x],is[x]},{x,-1,1}]

is/@x
N[fun/@x]
Function[ξ,Evaluate[D[is[ξ],ξ]]]/@x
N[Dfun/@x]

Function[ξ,Evaluate[D[is[ξ],{ξ,2}]]]/@x
N[DDfun/@x]