compattazione di matrice a banda e jacobi

This commit is contained in:
2014-11-01 18:02:59 +01:00
parent b07d220762
commit 8c6af09b7c
5 changed files with 182 additions and 61 deletions

View File

@@ -1,61 +1 @@
&% completa risoluzione di un sistema lineare usando la riduzione
% in matrice triangolare superiore con gauss pivoting parziale
% e algoritmo di bottom up con sostituzione
U=[0,20,30;0,5,3;0,56,34]; % matrice di input
b=[1;2;17]; %termini noti
n= length(b);
U= [U,b];
U
for i=1:1:n-1
x_max = max ( abs(U(i:n,i)) );
if x_max == 0
disp('errore matrice di input, det 0')
break
else
[x,y]= ind2sub(size(U), find (abs(U(i:n,i)) == x_max) );
x= x + i -1;
y = i;
if x~= i
U([i x],:) = U([x i],:);
end
for j=i+1:1:n
U(j,:) = U(j,:) + ( U(i,:) * (- U(j,i) / U(i,i) ) ) ;
end
end
end
if x_max ~= 0
b=U(:,n+1);
U=U(1:n,1:n);
x=[];
n= length(b);
x(n) = b(n)/U(n,n);
for i=n-1:-1:1
somma = 0;
for k=i+1:n
somma=somma+U(i,k) * x(k);
end
x(i) = (b(i) - somma)/ U(i,i);
end
disp ('La soluzione <EFBFBD> ')
x
end
A=[6,-1,-1,0,0,0,0,0,0;-1,6,-1,-2,0,0,0,0,0;-3,-1,6,0,-1,0,0,0,0;0,-1,0,6,-1,-1,0,0,0;0,0,-1,-1,6,-1,-1,0,0;0,0,0,-3,-1,6,0,-1,0;0,0,0,0,-1,0,6,-1,-2;0,0,0,0,0,-1,-1,6,-1;0,0,0,0,0,0,-1,-1,6]