# Licence de Maths Examen Final 2001 - 2002 # La méthode de Simpson # La fonction dont on veut approximer l'intégrale > f := x -> sin(x^2)+2; 2 f := x -> sin(x ) + 2 > student[leftbox](f(x),x=0..2,2); # un polynôme général de degrés deux > g := x -> A*x^2 + B*x + C;# 2 g := x -> A x + B x + C # Les deux courbes doivent coincider en début, milieu et fin de # l'interval > systeme := {f(0)=g(0), f(1)=g(1), f(2)=g(2)}; systeme := {2 = C, sin(1) + 2 = A + B + C, sin(4) + 2 = 4 A + 2 B + C} > solution := solve(systeme, {A, B, C}); solution := {C = 2, B = - 1/2 sin(4) + 2 sin(1), A = -sin(1) + 1/2 sin(4)} # Injectons une approximation de la solution dans la courbe g > gapprox:=subs(evalf(solution), g(x)); 2 gapprox := -1.219872233 x + 2.061343218 x + 2. # Tracons f et son approximation gapprox sur l'interval considéré > plot({f(x),gapprox},x=0..2); # Calculons les 3 aires : celle des 2 rectangles, celle de # l'approximation de Simpson, la véritable > airerectangles := evalf(f(0)*1 + f(1) *1); airerectangles := 4.841470985 > aireSimpson := int(gapprox, x=0..2); aireSimpson := 4.869693815 > aireVraie := evalf(int(f(x), x=0..2)); aireVraie := 4.804776490 > > # La décomposition LU > read `U:\\2001-02\\lmaths\\LU.txt`; Warning, new definition for norm Warning, new definition for trace Low := proc(n) local M, i, j; M := matrix(n, n); for j to n do for i to j - 1 do M[i, j] := 0 od; M[j, j] := 1 od; eval(M) end Up := proc(n) local M, i, j; M := matrix(n, n); for i to n do for j to i - 1 do M[i, j] := 0 od od; eval(M) end LU1 := proc(A) local n, L, U, B; n := coldim(A); L := Low(n); U := Up(n); B := evalm((L &* U) - A); B := map(op, {entries(B)}); assign(solve(B)); eval(L), eval(U) end LU2 := proc(A) local n, L, U, B, i, j; n := coldim(A); L := Low(n); U := Up(n); B := evalm((L &* U) - A); for j to n do for i to n do assign(solve({eval(B[i, j])})) od od; eval(L), eval(U) end > M := randmatrix(3,3); [-85 -55 -37] [ ] M := [-35 97 50] [ ] [ 79 56 49] > LU1(M); [-85 -55 -37 ] [ 1 0 0] [ ] [ ] [ 2034 1109 ] [7/17 1 0] [ 0 ---- ---- ] [ ], [ 17 17 ] [-79 83 ] [ ] [--- ---- 1] [ 121529] [85 2034 ] [ 0 0 ------] [ 10170 ] > LU2(M); [-85 -55 -37 ] [ 1 0 0] [ ] [ ] [ 2034 1109 ] [7/17 1 0] [ 0 ---- ---- ] [ ], [ 17 17 ] [-79 83 ] [ ] [--- ---- 1] [ 121529] [85 2034 ] [ 0 0 ------] [ 10170 ] > LUdecomp(M,L='l',U='u'); [-85 -55 -37 ] [ ] [ 2034 1109 ] [ 0 ---- ---- ] [ 17 17 ] [ ] [ 121529] [ 0 0 ------] [ 10170 ] > op(l); [ 1 0 0] [ ] [7/17 1 0] [ ] [-79 83 ] [--- ---- 1] [85 2034 ] > ?student >