analyse num
Embed Size (px)
TRANSCRIPT
// Analyse Numrique et Optimisation // M. Bnallal //
http://benallal.free.fr // //Version 1999/2000 - Cours Analyse
numrique et Optimisation - cole des Mines de D ouai //Version
2002/2003 - Cours Analyse numrique et Optimisation - Universit de
Montral // // // //Implmentation Scilab de la mthode de Jacobi //
Rsolution de systme du type A.X=B // par la mthode itrative de
JACOBI // Initialisation A=[-16 6 -2 -5; 3 10 -5 1; -4 1 18 2; 1 2
2 -14]; B=[-19; 1; 12; 1]; X0=[0.1; 0.1; 0.1; 0.1]; Xk=X0; iter=0;
max_it=500; tol = 0.0000000000001; // Conditionnement des matrices
D, L et U n=4; for i=1:n, for j=1:n, I(i,i)=1; D(i,i)=A(i,i); if
i>j then, L(i,j)=-A(i,j);, else L(i,j)=0;, end, if i tol,
iter=iter+1; Xk = Xkplus1; // JACOBI Xkplus1 = ( inv(D)*(L+U) * Xk
+ inv(D)* B); end; // Solution obtenue iter Xkplus1 //
////Implmentation Scilab de la mthode de Gauss-Seidel // Rsolution
de systme du type A.X=B // par la mthode itrative de GAUSS-SEIDEL
// Initialisation A=[-16 6 -2 -5; 3 10 -5 1; -4 1 18 2; 1 2 2 -14];
B=[-19; 1; 12; 1]; X0=[0.1; 0.1; 0.1; 0.1]; Xk=X0; iter=0;
max_it=500; tol = 0.0000000000001; // Conditionnement des matrices
D, L et U n=4; for i=1:n, for j=1:n, I(i,i)=1; D(i,i)=A(i,i); if
i>j then, L(i,j)=-A(i,j);, else L(i,j)=0;, end, if i tol,
iter=iter+1; Xk = Xkplus1; // GAUSS-SEIDEL Xkplus1 = ( inv(D-L) * U
* Xk + inv(D-L)* B); end; // Solution obtenue iter Xkplus1 // //
//Implmentation Scilab de la mthode de relaxation // Rsolution de
systme du type A.X=B // par la mthode itrative de relaxation //
Initialisation A=[-16 6 -2 -5; 3 10 -5 1; -4 1 18 2; 1 2 2 -14];
B=[-19;1; 12; 1]; X0=[0.1; 0.1; 0.1; 0.1]; Xk=X0; iter=0;
max_it=500; tol = 0.0000000000001; // Conditionnement des matrices
D, L et U n=4; for i=1:n, for j=1:n, I(i,i)=1; D(i,i)=A(i,i); if
i>j then, L(i,j)=-A(i,j);, else L(i,j)=0;, end, if i
iter=iter+1; Xk = Xkplus1; // RELAXATION Xkplus1 = ( inv(D-w*L) *
((1-w) * D end; // Solution obtenue iter Xkplus1 necessaire+ w*U) *
Xk + inv(D-w*L)* w*B); tol,+ w*U) * Xk + inv(D-w*L)*
w*B);//Implmentation Scilab de la mthode de la dichotomie 1 //
Recherche d'une racine d'un polynme // du type a.x^5 + b.x^4 +
c.x^3 + d.x^2 + e.x + f = 0 // par la mthode dichotomique 1 //
D'abord lancer (getf('C:\scliab\fonction.sci')) // le fichier
fonction.sci contiendra la fonction // polynomiale suivante : //
function [y]=f(x) // y =x^5 - 2*x^4 + 2*x^3 - 26*x^2 + 19*x + 22 //
Initialisation tol = 0.001; iter= 0; max_iter=500; s =
0.0000000001; // Borne [1,2] xa = 1; xb = 2; eps =
0.00000001;ya=f(xa); // itrations suivantes while abs(xb - xa) >
2 * eps, iter=iter+1; xc = 0.5 * (xa + xb); yc = f(xc); if (yc*ya)
< 0 then, xb = xc;, else ya = yc; xa = xc;, end, end; //
Solution obtenue iter xc//Implmentation Scilab de la mthode de la
dichotomie 2 // Recherche d'une racine d'un polynme // du type
a.x^5 + b.x^4 + c.x^3 + d.x^2 + e.x + f = 0 // par la mthode
dichotomique 2 // d'abord lancer (getf('C:\scliab\fonction.sci'))
// pour la fonction polynomile suivante // function [y]=f(x) // y
=x^5 - 2*x^4 + 2*x^3 - 26*x^2 + 19*x + 22 // Initialisation tol =
0.001; iter= 0; max_iter=50; s = 0.0000000001; // Borne [1,2] xa =
1; xb = 2; eps = 0.00000001; ya=f(xa); // itrations suivantes while
abs(xb - xa) > 2 * eps, iter=iter+1; xc = 0.5 * (xa + xb)- s; xd
= xc + 2 * s; yc = f(xc); yd = f(xd); if yc