Algoritme: Newtons interpolationsmetode

Opgave 15 i afsnit 18.2
 (+ andre opgaver i afsnit 18.2: erstat  f[x_] med det relevante udtryk).

Clear[f,x,x0]

f[x_]:=Cot[x]-Sin[x]

Plot[f[x],{x,0.5,2}]

f'[x]

g[x_] = x - f[x]/f'[x]

Simplify[%]

x0=2;
x1=Table[x0=N[g[x0],15],{i,8}];

TableForm[%]

g1=ListPlot[x1,
PlotStyle->{PointSize[0.015],RGBColor[1,0,0]}]

N[FindRoot[f[x]==0,{x,1.0},AccuracyGoal->15, 
MaxIterations->25],15];

x2=x /. %

g2=Plot[x2,{x,0,8},
PlotStyle->{{Thickness[0.007],RGBColor[0,0,1]}}];

Show[g1,g2, PlotRange ->{0,1.2}];