Numerische Integration

Summierte Trapezregel

Trapezregel[f_, {x_, a_, b_}, 
        n_] := ((b - a)/(2  
                n)) ((f /. x -> a) + (f /. 
                  x -> b)) + ((b - 
                a)/n) (∑_(k = 1)^(n - 1))(f /. 
                x -> a + k (( b - a)/n))

int = 
      Table[N[Trapezregel[Sin[x], {x, 0, π}, (2^k)]], {k, 1, 
          10}]

(∫_0^π) Sin[x] \[DifferentialD]x

Summierte Simpsonregel

Simpsonregel[f_, {x_, a_, b_}, 
        n_] := ((b - a)/(3  
                n)) ((f /. x -> a) + (f /. 
                  x -> b)) + ((b - a)/(3  
                n)) (∑_(k = 1)^(n - 1))If[EvenQ[k], 2, 
                4] (f /. x -> a + k (( b - a)/n))

int = 
      Table[N[Simpsonregel[Sin[x], {x, 0, π}, (2^k)]], {k, 1, 
          10}]

Legendre-Polynome

Table[LegendreP[n, x], {n, 0, 10}]

Normiert[p_, x_] := 
      Expand[p/Coefficient[p, x, Exponent[p, x]]]

Table[Normiert[LegendreP[n, x], x], {n, 0, 10}]

Erzeugen durch Gram-Schmidt

L[0] = 1; L[1] = x;

n = 2; 
    L[n] = (∑_(k = 0)^n) a[k] (x^k);
sol = 
        Solve[Append[
            Table[(∫_(-1)^1) L[
                      2] (x^k) \[DifferentialD]x == 0, {k, 0, 
                n - 1}], a[n] == 1], 
          Table[a[k], {k, 0, n}]];
L[n] = L[n] /. sol[[1]]

n = 3; 
    L[n] = (∑_(k = 0)^n) a[k] (x^k);
sol = 
        Solve[Append[
            Table[(∫_(-1)^1) L[
                      n] (x^k) \[DifferentialD]x == 0, {k, 0, 
                n - 1}], a[n] == 1], 
          Table[a[k], {k, 0, n}]];
L[n] = L[n] /. sol[[1]]

n = 4; 
    L[n] = (∑_(k = 0)^n) a[k] (x^k);
sol = 
        Solve[Append[
            Table[(∫_(-1)^1) L[
                      n] (x^k) \[DifferentialD]x == 0, {k, 0, 
                n - 1}], a[n] == 1], 
          Table[a[k], {k, 0, n}]];
L[n] = L[n] /. sol[[1]]

n = 5; 
    L[n] = (∑_(k = 0)^n) a[k] (x^k);
sol = 
        Solve[Append[
            Table[(∫_(-1)^1) L[
                      5] (x^k) \[DifferentialD]x == 0, {k, 0, 
                n - 1}], a[n] == 1], 
          Table[a[k], {k, 0, n}]];
L[n] = L[n] /. sol[[1]]

Table[L[n], {n, 0, 5}]

Table[Normiert[LegendreP[n, x], x], {n, 0, 5}]

Plot[Evaluate[Table[L[n], {n, 0, 5}]], {x, -1, 1}]

Gaußsche Quadraturformeln

n = 1;
sol = Solve[L[n + 1] == 0, x];
sol2 = 
      Solve[tab = 
          Append[Table[(∑_(k = 0)^n)(L[j] /. sol[[k + 1]])*
                    A[k] == 0, {j, 
                n}], (∑_(k = 0)^n) A[k] == 2 ], 
        Table[A[k], {k, 0, n}]]

tab

(∑_(k = 0)^n)(A[k] /. sol2[[1]])*
        f[x /. sol[[k + 1]]]

n = 2;
sol = Solve[L[n + 1] == 0, x];
sol2 = 
      Solve[tab = 
          Append[Table[(∑_(k = 0)^n)(L[j] /. sol[[k + 1]])*
                    A[k] == 0, {j, 
                n}], (∑_(k = 0)^n) A[k] == 2 ], 
        Table[A[k], {k, 0, n}]]

tab

(∑_(k = 0)^n)(A[k] /. sol2[[1]])*
        f[x /. sol[[k + 1]]]

n = 3;
sol = Solve[L[n + 1] == 0, x];
sol2 = 
      Solve[tab = 
          Append[Table[(∑_(k = 0)^n)(L[j] /. sol[[k + 1]])*
                    A[k] == 0, {j, 
                n}], (∑_(k = 0)^n) A[k] == 2 ], 
        Table[A[k], {k, 0, n}]]

N[%]

(∑_(k = 0)^n)(A[k] /. sol2[[1]])*
          f[x /. sol[[k + 1]]] // N