Professional Documents
Culture Documents
// 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<j then, U(i,j)=-A(i,j);,
else U(i,j)=0;, end ;
end ; end;
// premire itration
// JACOBI
Xkplus1 = ( inv(D)*(L+U) * Xk + inv(D)* B);
// itrations suivantes
while norm(Xkplus1 - Xk)/norm(Xk) > tol,
iter=iter+1;
Xk = Xkplus1;
// JACOBI
Xkplus1 = ( inv(D)*(L+U) * Xk + inv(D)* B);
end;
// Solution obtenue
iter
Xkplus1
//
//
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<j then, U(i,j)=-A(i,j);,
else U(i,j)=0;, end ;
end ; end;
//
//
//
//
//
//
THEOREME
Pour toute matrice A, une condition
de convergence
est que 0 < w < 2.
premire itration
RELAXATION
w=1.1
Xkplus1 = ( inv(D-w*L) * ((1-w) * D
// itrations suivantes
while norm(Xkplus1 - Xk)/norm(Xk) >
iter=iter+1;
Xk = Xkplus1;
// RELAXATION
Xkplus1 = ( inv(D-w*L) * ((1-w) * D
end;
// Solution obtenue
iter
Xkplus1
necessaire
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
max_iter=50;
s = 0.0000000001;
nb_dor = 0.5*(sqrt(5) - 1)
// Borne [1,2]
xa = 1; xb = 2; eps = 0.00000001;
xc = xa + (1-nb_dor)*(xb-xa);
xd = xa + nb_dor*(xb-xa);
// itrations suivantes
while abs(xb - xa) > eps,
iter=iter+1;
yc = f(xc);
yd = f(xd);
if yc > yd then, xa = xc;
xc = xd;
xd = xa + nb_dor*(xb-xa);,
else xb = xd;
xd = xc;
xc = xa + (1-nb_dor)*(xb-xa);, end,
end;
// Solution obtenue
iter
x
//IImplmentation Scilab de la mthode de Newton
// Recherche d'une solution d'un systme
// d'quation non linaire
// par la mthode de Newton
// d'abord lancer (getf('C:\scliab\fonction.sci'))
// pour la fonction suivante
//function [y1,y2,y3] = f(x)
//y1 = 4*(x(1)^2 + x(2)^2) - 2*x(1)*x(2) - 6*(x(1) + x(2));
//y2 = x(1)^3 + 2*x(2)^2 - 1
//y3 = 5*x(2)^3 + x(1)^2 - 2*x(1)*x(2) - 4
//function [dy1_x1,dy1_x2,dy2_x1,dy2_x2,dy3_x1,dy3_x2] =df(x)
//dy1_x1 = 8*x(1) - 2*x(2) -6;
//dy1_x2 = 8*x(2) - 2*x(1) -6;
//dy2_x1 = 3*x(1)^2;
//dy2_x2 = 4*x(2);
//dy3_x1 = 2*x(1) - 2*x(2);
//dy3_x2 = 15*x(2)^2 - 2*x(1);
// Initialisation
iter= 0; max_iter=500; tol = 0.0000000001;
// vecteur initiale
Xk = [0.1 ; 0.1];
// premire itration
[y1,y2,y3] = f(Xk);
y =[y1;y2;y3]
[dy1_x1,dy1_x2,dy2_x1,dy2_x2,dy3_x1,dy3_x2]= df(Xk);
J = [dy1_x1,dy1_x2;
dy2_x1,dy2_x2;
dy3_x1,dy3_x2]
// resolution du systme J(x).delta(x) = -R(x)
deltax = - J \ y;
Xkplus1 = Xk + deltax;
// itrations suivantes
while norm(Xkplus1 - Xk)/norm(Xk) > tol,
iter=iter+1;
Xk = Xkplus1;
[y1,y2,y3] = f(Xk);
y =[y1;y2;y3];
// Calcul de la jacobienne
[dy1_x1,dy1_x2,dy2_x1,dy2_x2,dy3_x1,dy3_x2]= df(Xk);
J = [dy1_x1,dy1_x2;
dy2_x1,dy2_x2;
dy3_x1,dy3_x2];
// resolution du systme J(x).delta(x) = -R(x)
deltax = - J \ y;
Xkplus1 = Xk + deltax;
end;
// Solution obtenue
iter
Xkplus1