thomas tridiagonal and spectral radius

This commit is contained in:
2014-11-02 16:48:39 +01:00
parent 0aff089106
commit fa0d6f3f4f
7 changed files with 123 additions and 3 deletions

View File

@@ -15,7 +15,7 @@ function [U,b] = convert_matrix_to_triangular_matrix_gauss_naif (U,b)
ok=1;
% convertiamo la matrice in una triangolare superiore
% convertiamo la matrice
for i=1:1:n-1
if abs(U(i,i)) <= eps * norma

View File

@@ -15,7 +15,7 @@ function [U,b,pivot] = convert_matrix_to_triangular_matrix_gauss_pivoting (U,b)
pivot = 1:1:n;
pivot = pivot';
% convertiamo la matrice in una triangolare superiore
% convertiamo la matrice
for i=1:1:n-1
x_max = max ( abs(U(i:n,i)) );

View File

@@ -0,0 +1,23 @@
%risoluzione matrice triangolare inferiore con algoritmo
% di sostituzione botton up (all'indietro)
%example input
% U=[1,0,0;1,1,0;1,5,1];
% b=[5;-8;-2];
function[x] = linear_system_resolver_lower_triangular_matrix(U,b)
x=[];
n= length(b);
x(1) = b(1)/U(1,1);
for i=2:1:n
somma = 0;
for k=i-1:-1:1
somma=somma+U(i,k) * x(k);
end
x(i) = (b(i) - somma)/ U(i,i);
end
end

View File

@@ -6,7 +6,7 @@
% b=[5;-8;-2];
function[x] = linear_system_resolver_triangular_matrix(U,b)
function[x] = linear_system_resolver_upper_triangular_matrix(U,b)
x=[];
n= length(b);

View File

@@ -0,0 +1,54 @@
% questo algoritmo prende in input una matrice tridiagonale
% e i termini noti : ax=b e ne calcola la soluzione x
% usando il metodo di thomas lineare
%U=[10,20,30;1,5,3;4,56,34]; matrice di input
%b=[1;2;17]; termini noti
function [x] = thomas_tridiagonal_matrix_no_pivoting (U,b)
n= length(b); % lunghezza del vettore dei termini noti o numero equazioni
norma = norm(U,inf);
ok=1;
% convertiamo la matrice
for i=1:1:n-1
if abs(U(i,i)) <= eps * norma
disp('WARNING: Elemento prossimo allo zero sulla diagonale')
end
if U(i,i) == 0
ok=0;
break
end
j=i+1;
m= U(j,i) / U(i,i);
U(j,i+1) = U(j,i+1) + ( U(i,i+1) * (- m ) ) ;
U(j,i)=m;
end
if ok == 0 || U(n,n) == 0
disp('impossibile convertire')
x=[];
else
if abs(U(n,n)) <= eps * norma
disp('WARNING: Elemento prossimo allo zero sulla diagonale')
end
Low=tril(U,-1) + eye (size(U));
Upp=triu(U);
%1 ly=b
%2 ux=y
y = linear_system_resolver_lower_triangular_matrix(Low,b);
x = linear_system_resolver_upper_triangular_matrix(Upp,y);
end
end