Einführung in Mathematica XII

Interpolation - Newtonsche Methode

© Jürgen Schnack, 2012/04/26

Fiktive Daten

data={{0.0,-1.0},{1.0,0.0},{2.0,1.0},
{3.0,8.0},{4.0,27.0}}

LP1=ListPlot[data,PlotStyle->{Hue[0],
PointSize[0.02]},PlotRange->{-2,30},BaseStyle->{FontFamily->"Helvetica",FontSize->18}]

Koeffizienten des Polynoms

a=Table[0.0,{n,1,Length[data]}]

Werden im weitern berechnet.

Polynom nullten Grades

x0=data[[1,1]]
f0=data[[1,2]]
a[[1]]=f0;
P0[x_]=a[[1]];

PlotP0=Plot[P0[x],{x,0,4},
PlotRange->{-2,30},
PlotStyle->{Black,Thick},BaseStyle->{FontFamily->"Helvetica",FontSize->18}]

Show[LP1,PlotP0]

Polynom ersten Grades

x1=data[[2,1]]
f1=data[[2,2]]
f01=((f1-f0)/(x1-x0));
a[[2]]=f01;
P1[x_]=a[[1]]+a[[2]]*(x-x0);

PlotP1=Plot[P1[x],{x,0,4},
PlotRange->{-2,30},
PlotStyle->{Green,Thick},BaseStyle->{FontFamily->"Helvetica",FontSize->18}]

Show[LP1,PlotP1]

Polynom zweiten Grades

x2=data[[3,1]]
f2=data[[3,2]]
f12=((f2-f1)/(x2-x1));
f012=((f12-f01)/(x2-x0));
a[[3]]=f012;
P2[x_]=a[[1]]+a[[2]]*(x-x0)+a[[3]]*(x-x0)*(x-x1);

PlotP2=Plot[P2[x],{x,0,4},
PlotRange->{-2,30},
PlotStyle->{Blue,Thick},BaseStyle->{FontFamily->"Helvetica",FontSize->18}]

Show[LP1,PlotP2]

Polynom dritten Grades

x3=data[[4,1]]
f3=data[[4,2]]
f23=((f3-f2)/(x3-x2));
f123=((f23-f12)/(x3-x1));
f0123=((f123-f012)/(x3-x0));
a[[4]]=f0123;
P3[x_]=a[[1]]+a[[2]]*(x-x0)+a[[3]]*(x-x0)*(x-x1)+
a[[4]]*(x-x0)*(x-x1)*(x-x2);

PlotP3=Plot[P3[x],{x,0,4},
PlotRange->{-2,30},
PlotStyle->{Magenta,Thick},BaseStyle->{FontFamily->"Helvetica",FontSize->18}]

Show[PlotP3,LP1]

Koeffizienten des Polynoms

TableForm[a]

Den fünften Koeffizienten haben wir noch nicht berechnet.
Wie groß wird er wohl ausfallen?

Nonlinear Fit I

Wir machen den Test.

P4[x_,b_,c_,d_,e_,f_]=b+c*(x-x0)+d*(x-x0)*(x-x1)+
e*(x-x0)*(x-x1)*(x-x2)+
f*(x-x0)*(x-x1)*(x-x2)*(x-x3)

Para4=FindFit[data,P4[x,b,c,d,e,f],{b,c,d,e,f},x]

Nonlinear Fit II

PlotP4=Plot[P4[x,b,c,d,e,f]/.Para4,{x,0,4},PlotRange->{-2,30},PlotStyle->{Cyan,Thick},BaseStyle->{FontFamily->"Helvetica",FontSize->18}]

Show[PlotP4,LP1]

Interpolating Function

InterpolatingFunction

InterpolatingFunction does a Piecewise polynomial interpolation,
see help.