(*EXAMPLE II What minimal power n of Pn we need to decently interpolate a smooth function?By "decently" I mean that the main features are reproduced,such as all maxs and mins.*)

F[x_]:=Sin[x];

a=Pi/2;b=(7/2)*Pi;

plotfunction=Plot[F[x],{x,a,b},PlotStyle->{Hue[1],Thickness[0.01]},PlotLabel->"Original function",DisplayFunction->Identity];

(*Set sample data points-- nodes.*)

n=7;h=(b-a)/n;(*define sample points as values of F[x].Try n=2,...7*)

data=Table[N[{x,F[x]}],{x,a,b,h}];

plotdata=ListPlot[data,PlotLabel->"Data points",PlotStyle->{PointSize[Large],Black}];

Show[plotfunction,plotdata]

fit=InterpolatingPolynomial[data,x];



plotfit=Plot[fit,{x,a,b},PlotStyle->{Hue[0.5],Thickness[0.005]},PlotLabel->"interpolation",PlotLegends->LineLegend[{Blue},{"interpolation"}]];


Show[plotfunction,plotdata,plotfit,PlotLabel->{"red - original f(x) ,
blue - interpolation, black - nodes (sample points) "},Prolog->AbsolutePointSize[5],DisplayFunction->$DisplayFunction, PlotRange -> All]


Print[]
Print[]

Print["Interpolating polynomial Pn =   " fit]
Print[]
Print[" Or, in simplified form, Pn = " Expand[Simplify[fit]]]

Print[]

(*So,what is the minimal degree of Pn neccessary for a decent interpolation of this function?If it has 2 extrema,then derivative=0 at two points=>(Pn)'=P2,and so the minimum power is P3.Try P4 and look at the breakdown of the coefficients.How large is the coefficient infront of x^4?What does that mean?The general principle is "Like likes like".So,for the above function,do you want to try odd or even degree polynomials?*)