Lösungen/Solutions/I1S2AnUe/Ex8

L = Lektion/ Leçon   -- Sprechstunde / heures de consultation
W = Work / Arbeit / Travail
A=Anhang/Annexe/Appendice

Probl/Ex 1      W

a

Remove["Global`*"]

data = {{1, 4}, {2, 5}, {3, 6}, {4, 7}, {5, 3}, {7, 3}, {8, 5}, {9, 
            1}, {10, 4}};

p[x_, i_] := Sum[a[k] x^k, {k, 0, i - 1}]

expon = Length[data]

p[x, expon]

tab1 = 
      Table[p[data[[s]][[1]], 
            expon] == data[[s]][[2]], {s, 1, 
          Length[data]}]

solv = Solve[tab1, Table[a[k], {k, 0, expon}]] // Flatten

q[x_] := p[x, expon] /. solv;
q[x]

ListPlot[data];

points = Map[Point, data]

ap = Flatten[Prepend[points, {PointSize[0.02]}]]

Plot[q[x], {x, -1, 11}, Epilog -> ap];

b

Remove["Global`*"]

data = {{1, 0}, {2, 0}, {3, 0}, {4, 10}, {5, 10}, {7, 0}, {8, 0}, {9, 
            0}, {10, 0}, {11, 0}, {12, 0}};

p[x_, i_] := Sum[a[k] x^k, {k, 0, i - 1}]

expon = Length[data]

p[x, expon]

tab1 = 
      Table[p[data[[s]][[1]], 
            expon] == data[[s]][[2]], {s, 1, 
          Length[data]}]

solv = Solve[tab1, Table[a[k], {k, 0, expon}]] // Flatten

q[x_] := p[x, expon] /. solv;
q[x]

points = Map[Point, data]

ap = Flatten[Prepend[points, {PointSize[0.02]}]]

pl1 = Plot[q[x], {x, -1, 13}, Epilog -> ap];

q1[x_] = q[x]

c

data = {{-4, 0}, {-3, 0}, {-2, 0}, {-1, 0}, {1, 
            0}, {2, 0}, {3, 0}, {4, 10}, {5, 10}, {7, 0}, {8, 0}, {9, 
            0}, {10, 0}, {11, 0}, {12, 0}, {13, 0}, {14, 0}};

p[x_, i_] := Sum[a[k] x^k, {k, 0, i - 1}]

expon = Length[data]

p[x, expon]

tab1 = 
      Table[p[data[[s]][[1]], 
            expon] == data[[s]][[2]], {s, 1, 
          Length[data]}]

solv = Solve[tab1, Table[a[k], {k, 0, expon}]] // Flatten

q[x_] := p[x, expon] /. solv;
q[x]

points = Map[Point, data]

ap = Flatten[Prepend[points, {PointSize[0.02]}]]

pl2 = Plot[q[x], {x, -4, 15}, Epilog -> ap];

Show[pl1, pl2];

diff[x_] := q[x] - q1[x]

Plot[diff[x], {x, -4, 15}, Epilog -> ap];

2

Remove["Global`*"]

a

f[x_] := 1 + x + x^2 + x^3 + x^4;  a = 0;  b = 7;

int = Integrate[f[x] , {x, a, b}] // N

n = 10;
Δx = (b - a)/n;  
    u[k_] := a + k Δx;
Su = 
        Sum[f[u[k]]* Δx, {k, 0, n - 1}] // 
          N;
So = 
        Sum[f[u[k]]* Δx, {k, 1, n}] // 
          N;
{Su, int, So}

b

n = 100;
Δx = (b - a)/n;  
    u[k_] := a + k Δx;
Su = 
        Sum[f[u[k]]* Δx, {k, 0, n - 1}] // 
          N;
So = Sum[f[u[k]]* Δx, {k, 1, n}] // N; {Su, int, 
      So}

c

n = 1000;
Δx = (b - a)/n;  
    u[k_] := a + k Δx;
Su = 
        Sum[f[u[k]]* Δx, {k, 0, n - 1}] // 
          N;
So = Sum[f[u[k]]* Δx, {k, 1, n}] // N; {Su, int, 
      So}

d

n = 10000;
Δx = (b - a)/n;  
    u[k_] := a + k Δx;
Su = 
        Sum[f[u[k]]* Δx, {k, 0, n - 1}] // 
          N;
So = Sum[f[u[k]]* Δx, {k, 1, n}] // N; {Su, int, 
      So}

Sm = 
      Sum[(f[u[k]] + f[u[k + 1]])/2 * Δx, {k, 0, n - 1}] // 
        N

e

n = 100; Δx = (b - a)/n;  
    u[k_] := a + k Δx; 
    Sm = Sum[(f[u[k]] + f[u[k + 1]])/2 * Δx, {k, 0, 
            n - 1}] // N

f

n = 10; Δx = (b - a)/n;  
    u[k_] := a + k Δx;

p[x_, n_] := a2[n] x^2 + a1[n] x + a0[n] ;

tab3 = Flatten[Table[{a0[n], a1[n], a2[n]}, {n, 0, 4}]]

Table[{u[k], k}, {k, 0, 10}] // N

{p[u[k], k] == f[u[k]], p[u[k + 1], k] == f[u[k + 1]], 
      p[u[k + 2], k] == f[u[k + 2]]}

p[u[2], 0] == f[u[2]]

test = 
      Table[{k, u[2  k], u[2  k + 1], u[2  k + 2]}, {k, 0, 4}] // 
        N

flat = 
      Flatten[Table[{p[u[2  k], k] == f[u[2  k]], 
            p[u[2  k + 1], k] == f[u[2  k + 1]], 
            p[u[2  k + 2], k] == f[u[2  k + 2]]}, {k, 0, 4}]]

solv = Solve[flat, tab3] // Flatten

p1[x_, n_] := p[x, n] /. solv

Table[p1[x, n], {n, 0, 4}]

pf = Plot[f[x], {x, a, b}];

pp0 = 
        Plot[p1[x, 0], {x, a + 0*2 Δx, 
            a + 1*2 Δx}];

{a + 0*2 Δx, a + 1*2 Δx} // N

pp1 = 
        Plot[p1[x, 1], {x, a + 1*2 Δx, 
            a + 2*2 Δx}];

{a + 1*2 Δx, a + 2*2 Δx} // N

pp2 = 
        Plot[p1[x, 2], {x, a + 2*2 Δx, 
            a + 3*2 Δx}];

{a + 2*2 Δx, a + 3*2 Δx} // N

pp3 = 
        Plot[p1[x, 3], {x, a + 3*2 Δx, 
            a + 4*2 Δx}];

{a + 3*2 Δx, a + 4*2 Δx} // N

pp4 = 
        Plot[p1[x, 4], {x, a + 4*2 Δx, 
            a + 5*2 Δx}];

{a + 4*2 Δx, a + 5*2 Δx} // N

Show[pf, pp0, pp1, pp2, pp3, pp4];

int = Integrate[f[x] , {x, a, b}] // N

intq = 
      Sum[Integrate[
          p1[x, n], {x, 
            2  n Δx,  (2  n + 2) Δx}], {n, 
          0, 4}]

intqN = N[intq]

n = 10;
Δx = (b - a)/n;  
    u[k_] := a + k Δx;
Su = 
        Sum[f[u[k]]* Δx, {k, 0, n - 1}] // 
          N;
So = 
        Sum[f[u[k]]* Δx, {k, 1, n}] // 
          N;
{Su, int, intqN, So}