Ecrit par Andrea le Novembre 24, 2000 at 22:03:44:
En réponse à: Methode de relaxation écrit par nordine le Novembre 18, 2000 at 13:47:06:
Si vous utilisez Matlab, ici il y a un bon programme pour resoudre un systeme par la metode de relaxation.
Salut, Andrea.
function [x,w,iters]=sor(a,b,w,x,e,verbose);
%This solves the system Ax=b using the successive overrelaxation method
%w is the extrapolation/interpolation factor
%x is the intial starting vector
%e is the error term allowed for convergence
%verbose denotes whether or not output is given
% w will return the optimal extrapolation factor
% iters will return the number of iterations used
% set up default values
if nargin<6
verbose=0;
if nargin<5
e=0.000001;
if nargin <4
x=zeros(d,1);
if nargin<3;
w=1.5;
if nargin<2
error('Manque de Input')
end
end
end
end
end
d=size(a,1);
err=e+1;
iters=0;
while err>e;
oldx=x;
for i=1:d
s=sum(a(i,1:d)'.*x)-a(i,i).*x(i,1);
x(i,1)=w.*(b(i,1)-s)/a(i,i)+(1-w).*x(i,1);
end
err=max(abs(x-oldx));
iters=iters+1;
end
if verbose>0;
disp(iters);
end