Skip to content

Commit

Permalink
Add functions core.preconditioners.{jacobi,ssor}
Browse files Browse the repository at this point in the history
  • Loading branch information
SeSodesa committed Oct 18, 2023
1 parent 0e8e166 commit fa281e2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions +core/+preconditioners/jacobi.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function prec = jacobi ( A )
%
% prec = jacobi ( A )
%
% Computes the Jacobi preconditioner for the matrix A of a system Ax = b.
%

arguments
A (:,:)
end

prec = diag ( diag ( A ) ) \ eye ( size ( A ) ) ;

end % function
32 changes: 32 additions & 0 deletions +core/+preconditioners/ssor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function prec = ssor ( A, kwargs )
%
% prec = ssor ( A, kwargs )
%
% Computes the SSOR preconditioner for the matrix A of a system Ax = b.
%
% kwargs:
%
% - coeff = 1
%
% The preconditioner constant used in the computation. The default value of 1
% corresponds to the Gauss--Seidel preconditioner.
%

arguments
A (:,:)
kwargs.coeff (1,1) double { mustBeInRange(kwargs.coeff, 0, 2) } = 1
end

L = tril ( A ) ;

U = triu ( A ) ;

D = diag ( diag ( A ) ) ;

invD = D \ eye ( size ( D ) ) ;

coeff = kwargs.coeff ;

prec = ( D + coeff * L ) * invD * ( D + coeff * U ) ;

end % function

0 comments on commit fa281e2

Please sign in to comment.