Lagrange-Interpolation

Lagrange[a_, 
        x_] := (∑_(k = 1)^(Length[a]))(a[[k, 2]]*
            Product[((x - a[[j, 1]])/(a[[k, 1]] - a[[j, 1]])), {j, 1, k - 1}]*
            Product[((x - a[[l, 1]])/(a[[k, 1]] - a[[l, 1]])), {l, k + 1, Length[a]}])

LagrangePlot[a_, x_] := 
      Module[{f, plot1, plot2}, f = Lagrange[a, x]; 
        plot1 = Plot[
            f, {x, Min[Transpose[daten][[1]]], 
              Max[Transpose[daten][[1]]]}, 
            DisplayFunction -> Identity]; 
plot2 = 
          Graphics[{PointSize[0.03], 
              Map[Point, daten]}]; 
Show[plot1, plot2, 
          DisplayFunction -> $DisplayFunction]
]

daten = {{-2, 0}, {-1, 0}, {0, 0}, {1, 1}, {2, 0}}

Lagrange[daten, x]

LagrangePlot[daten, x]

daten = {{-2, 0}, {-1, 1}, {0, 0}, {1, 1}, {2, 0}}

Lagrange[daten, x]

Factor[%]

Expand[%]

LagrangePlot[daten, x]

daten = {{0, 1.5}, {0.5, 2.8}, {1, 0.5}, {2, 2.3}}

Expand[Lagrange[daten, x]]

LagrangePlot[daten, x]

daten = Table[{x, Sin[x]}, {x, -π, π, (π/2)}]

f = Factor[Lagrange[daten, x]]

Expand[f]

N[%]

Plot[{Sin[x], f}, {x, -π, π}]

Plot[{Sin[x], f}, {x, -2 π, 2  π}]

g[x_] := (x/(1 + (x^3)))

daten = Table[{x, g[x]}, {x, 0, 2}]

f = Factor[Lagrange[daten, x]]

N[f] // Expand

Plot[{g[x], f}, {x, 0, 2}]

Newton-Interpolation

daten = {{1, 1}, {3, 2}, {6, 3}}

InterpolatingPolynomial[daten, x]

daten = {{1, 1}, {3, 2}, {6, 3}, {10, 4}}

InterpolatingPolynomial[daten, x]

Fehlerrechnung

daten = Table[{x, Sin[x]}, {x, -π, π, (π/2)}]

f = Factor[Lagrange[daten, x]]

Plot[{Sin[x], f}, {x, -π, π}]

Plot[Abs[Sin[x] - f], {x, -π, π}]

Fehlerfunktion

Plot[(1/(5!)) (∏_(k = -2)^2) Abs[
            x - k  (π/2)], {x, -π, π}]

Oszillation

daten = {{0, 0}, {4, 0.1}, {7, 0.3}, {8, 0.8}, {9, 2}, {10, 
          10}}

f = Lagrange [daten, x]

plot1 = LagrangePlot[daten, x]