aggiunto contatori di operazioni ai metodi iterativi di gauss-seidel e jacobi

This commit is contained in:
2014-11-19 11:19:45 +01:00
parent 84eca0228b
commit 922b2f22bf
4 changed files with 17 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ function [x0,err,niter,ier] = gauss_seidel_abs (U,b,x0,toll,nmax)
niter = 0;
ier = 0;
err = inf;% err infinito per superare subito toll
counter = 0;
while ( niter < nmax ) && ( err >= toll)
x0_old = x0;
@@ -30,9 +31,11 @@ function [x0,err,niter,ier] = gauss_seidel_abs (U,b,x0,toll,nmax)
for k=1:i-1
partial_sum = partial_sum + ( U(i,k) * x0(k));
counter = counter + 1;
end
for k=i+1:n
partial_sum2 = partial_sum2 + ( U(i,k) * x0(k));
counter = counter + 1;
end
x0(i) = (b(i) - partial_sum - partial_sum2)/U(i,i) ;
end
@@ -45,5 +48,6 @@ function [x0,err,niter,ier] = gauss_seidel_abs (U,b,x0,toll,nmax)
disp('Warning: Massimo numero di step raggiunti')
ier = 1;
end
counter
end

View File

@@ -21,6 +21,7 @@ function [x0,err,niter,ier] = gauss_seidel_abs_ordered_csr (elementi,colonne,ind
niter = 0;
ier = 0;
err = inf;% err infinito per superare subito toll
counter = 0;
while ( niter < nmax ) && ( err >= toll)
x0_old = x0;
@@ -35,9 +36,12 @@ function [x0,err,niter,ier] = gauss_seidel_abs_ordered_csr (elementi,colonne,ind
end
for k=start:(stop -1)
partial_sum = partial_sum + (elementi(k) * x0(colonne(k)));
counter = counter + 1;
end
for k=(stop +1):(indice_riga(i+1) - 1)
partial_sum2 = partial_sum2 + (elementi(k) * x0(colonne(k)));
counter = counter + 1;
end
x0(i) = (b(i) - partial_sum - partial_sum2)/ elementi(stop) ;
end
@@ -50,5 +54,6 @@ function [x0,err,niter,ier] = gauss_seidel_abs_ordered_csr (elementi,colonne,ind
disp('Warning: Massimo numero di step raggiunti')
ier = 1;
end
counter
end

View File

@@ -22,6 +22,7 @@ function [x0,err,niter,ier] = jacobi_abs (U,b,x0,toll,nmax)
ier = 0;
err = inf;% err infinito per superare subito toll
x1 = x0;% solo per inizializzare
counter = 0;
while ( niter < nmax ) && ( err >= toll)
for i=1:n
@@ -30,9 +31,11 @@ function [x0,err,niter,ier] = jacobi_abs (U,b,x0,toll,nmax)
for k=1:i-1
partial_sum = partial_sum + ( U(i,k) * x0(k));
counter = counter + 1;
end
for k=i+1:n
partial_sum2 = partial_sum2 + ( U(i,k) * x0(k));
counter = counter + 1;
end
x1(i) = (b(i) - partial_sum - partial_sum2)/U(i,i) ;
end
@@ -46,5 +49,6 @@ function [x0,err,niter,ier] = jacobi_abs (U,b,x0,toll,nmax)
disp('Warning: Massimo numero di step raggiunti')
ier = 1;
end
counter
end

View File

@@ -22,6 +22,7 @@ function [x0,err,niter,ier] = jacobi_abs_ordered_csr (elementi,colonne,indice_ri
ier = 0;
err = inf;% err infinito per superare subito toll
x1 = x0;% solo per inizializzare
counter = 0;
while ( niter < nmax ) && ( err >= toll)
for i=1:n
@@ -35,9 +36,11 @@ function [x0,err,niter,ier] = jacobi_abs_ordered_csr (elementi,colonne,indice_ri
end
for k=start:(stop -1)
partial_sum = partial_sum + (elementi(k) * x0(colonne(k)));
counter= counter + 1;
end
for k=(stop +1):(indice_riga(i+1) - 1)
partial_sum2 = partial_sum2 + (elementi(k) * x0(colonne(k)));
counter = counter + 1;
end
x1(i) = (b(i) - partial_sum - partial_sum2)/ elementi(stop) ;
end
@@ -51,5 +54,6 @@ function [x0,err,niter,ier] = jacobi_abs_ordered_csr (elementi,colonne,indice_ri
disp('Warning: Massimo numero di step raggiunti')
ier = 1;
end
counter
end