Graphics Programs Reference
In-Depth Information
fork=1:n-1
%Eliminationphase
for i= 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);
b(i)= b(i) - lambda*b(k);
end
end
end
if nargout == 2; det = prod(diag(A)); end
fork=n:-1:1 %Backsubstitutionphase
b(k) = (b(k) - A(k,k+1:n)*b(k+1:n))/A(k,k);
end
x=b;
Multiple Sets of Equations
As mentionedbefore, it isfrequentlynecessary to solve the equations
Ax
=
b
for
severalconstant vectors.Let
there be
m
such
constant vectors, denotedby
b
1
,
b
2
,...,
b
m
and let the corresponding solutionvectors be
x
1
,
x
2
,...,
x
m
.We denote
multiple sets of equations by
AX
=
B
, where
x
1
x
m
b
1
b
m
X
=
x
2
···
B
=
b
2
···
are
n
m
matrices whose columnsconsist of solutionvectors and constant vectors,
respectively.
An economical way to handle such equations during the eliminationphase is
to include all
m
constant vectors in the augmented coefficient matrix,sothat they
aretransformed simultaneouslywith the coefficient matrix. The solutions are then
obtainedbyback substitutioninthe usual manner,one vectorat a time. It would quite
easy to make the corresponding changes in
gauss
. However, the LU decomposition
method, describedinthe next article, is more versatile in handling multiple constant
vectors.
×
EXAMPLE 2.3
Use Gauss elimination to solve the equations
AX
=
B
, where
⎡
⎣
⎤
⎦
⎡
⎣
⎤
⎦
6
−
4
1
−
14
22
A
=
−
4
6
−
4
B
=
36
−
18
1
−
4
6
6
7
Search WWH ::
Custom Search