Graphics Programs Reference
In-Depth Information
ifp˜=k
s = swapRows(s,k,p);
A = swapRows(A,k,p);
perm = swapRows(perm,k,p);
end
%--------------Elimination pass---------------
fori=k+1:n
if A(i,k) ˜= 0
lambda = A(i,k)/A(k,k);
A(i,k+1:n) = A(i,k+1:n) - lambda*A(k,k+1:n);
A(i,k) = lambda;
end
end
end
LUsolPiv
functionx=LUsolPiv(A,b,perm)
%SolvesL*U*b=x,whereAcontainsrow-wise
%permutationofLandUintheformA=[L\U].
% Vector 'perm' holds the row permutation data.
% USAGE: x = LUsolPiv(A,b,perm)
%----------Rearrange b, store it in x--------
if size(b) > 1; b = b'; end
n = size(A,1);
x=b;
fori=1:n;x(i)=b(perm(i));end
%--------Forward and back substitution--------
fork=2:n
x(k) = x(k) - A(k,1:k-1)*x(1:k-1);
end
fork=n:-1:1
x(k) = (x(k) - A(k,k+1:n)*x(k+1:n))/A(k,k);
end
When to Pivot
Pivoting has a couple of drawbacks. One of these is the increased cost of computation;
the otheris the destruction of the symmetry and banded structure of the coefficient
Search WWH ::




Custom Search