Graphics Programs Reference
In-Depth Information
The essential elements of a Gauss-Seidel algorithmwith relaxationare:
1. Carry out k iterations with
ω =
1 ( k
=
10 is reasonable).After the k th iteration
record
x ( k ) .
x ( k + p )
2.
Perform an additional p iterations( p
1) and record
after the last
iteration.
3.
Perform all subsequent iterations with
ω = ω opt , where
ω opt iscomputed from
Eq. (2.36).
gaussSeidel
The function gaussSeidel is an implementation of the Gauss-Seidel methodwith
relaxation. It automatically computes
1.
The usermust provide the function iterEqs thatcomputes the improved x from the
iterativeformulas in Eq. (2.35)—see Example 2.17.
ω
opt fromEq. (2.36) using k
=
10 and p
=
function [x,numIter,omega] = gaussSeidel(func,x,maxIter,epsilon)
%SolvesAx=bbyGauss-Seidelmethodwithrelaxation.
% USAGE: [x,numIter,omega] = gaussSeidel(func,x,maxIter,epsilon)
% INPUT:
% func = handle of function that returns improved x using
% the iterative formulas in Eq. (2.35).
% x = starting solution vector
% maxIter = allowable number of iterations (default is 500)
% epsilon = error tolerance (default is 1.0e-9)
% OUTPUT:
% x = solution vector
% numIter = number of iterations carried out
% omega
= computed relaxation factor
if nargin < 4; epsilon = 1.0e-9; end
if nargin < 3; maxIter = 500; end
k=10;p=1;omega=1;
for numIter = 1:maxIter
xOld = x;
x = feval(func,x,omega);
dx = sqrt(dot(x - xOld,x - xOld));
if dx < epsilon; return; end
if numIter == k; dx1 = dx; end
Search WWH ::




Custom Search