Sie sind auf Seite 1von 13

2.

1 Gauss-Jordan Elimination-11
Gill. RE.. Murray. W., and Wright, M.H. 1991, Numerical Linear Algebra and Optimization,
vol. 1 (Redwood City. CA: Addison-Wesley).
Stoer, J., and Bulirsch. R. 2002, Introduction to Numerical Analysis, 3rd ed. (New York:
Springer), Chapter 4.
Ueberhuber, C.W. 1997, Numerical Computation: Methods, Software, and Analysis, 2 vols.
(Berlin: Springer), Chapter 13.
Coleman, T.F., and Van Loan, C. 1988, Handbook for Matrix Computations (Philadelphia:
S.1-A.M.).
Forsythe, G.E., and Molex, C.B. 1967, Computer Solution of Linear Algebraic Systems
(Engle-wood Cliffs, NJ: Prentice-Hall).
Wilkinson, J.H., and Reinsch, C. 1971, Linear Algebra, vol. II of Handbook for Automatic
Computation (New York: Springer).
Westlake, J.R. 1968, A Handbook of Numerical Matrix Inversion and Solution of Linear
Equations (New York: Wiley).
Johnson, L.W., and Riess, R.D. 1982, Numerical Analysis, 2nd ed. (Reading, NIA:
AddisonWesley), Chapter 2.
Ralston, A., and Rabinowitz, R 1978, A First Course in Numerical Analysis, 2nd ed.;
reprinted 2001 (New York: Dover), Chapter 9.
2.1 Gauss-Jordan Elimination
Gauss-Jordan elimination is probably the way you learned to solve linear equa-tions in high
school. (You may have learned it as "Gaussian elimination. - but, strictly speaking, that term
refers to the somewhat different technique discussed in 2.2.) The basic idea is to add or
subtract linear combinations of theuntil each
I iven equations
equation contains only one of the unknowns, thus giving an immediate solution. You might
also have learned to use the same technique for calculating the inverse of a matrix.
For solving sets of linear equations, Gauss-Jordan elimination produces both the solution of
the equations for one or more right-hand side vectors b, and also the matrix inverse A'.
However, its principal deficiencies are (i) that it requires all the right-hand sides to be stored
and manipulated at the same time, and (ii) that when the inverse matrix is not desired. GaussJordan is three times slower than the best alternative technique for solving a single linear set
(2.3). The method's principal strength is that it is as stable as any other direct method,
perhaps even a bit more stable when full pivoting is used (see 2.1.2).

For inverting a matrix, Gauss-Jordan elimination is about as efficient as any other direct
method. We know of no reason not to use it in this application if you are sure that the matrix
inverse is what you really want.
You might wonder about deficiency (i) above: If we are getting the matrix in-verse anyway,
can't we later let it multiply a new right-hand side to get an additional solution'? This does
work, but it gives an answer that is very susceptible to roundoff error and not nearly as good
as if the new vector had been included with the set of right-hand side vectors ih the first
instance.
Thus, Gauss-Jordan elimination should not be your method of first choice for solving linear
equations. The decomposition methods in 2.3 are better. Why do -we discuss Gauss-Jordan
at all? Because it is straightforward, solid as a rock, and a good place for us to introduce the
important concept of pivoting which will also
~f
42

Chapter 2. Solution of Linear Algebraic Equations

be important for the methods described later. The actual sequence of operation,,, performed in
Gauss-Jordan elimination is very closely related to that performed by the routines in the next
two sections.
2.1.1 Elimination on Column-Augmented Matrices
For clarity, and to avoid writing endless ellipses(... ) we will write out equations only for the
case of four equations and four unknowns, and with three different right-hand side vectors
that are known in advance. You can write bigger matrices and extend the equations to the case
of N x N matrices, with M sets of right-hand side vectors, in completely analogous fashion.
The routine implemented below in 2.1.2 is, of course, general.
Consider the linear matrix equation
aoo

aol
Y02

a02
Y03

a03

X0

alo

all
Y12

a12
Y13

a13

X10

a2o

a21
Y21

a22
Y22

a23
Y23

X20

X21

X22

YO)o

_a30

a31
Y31

a32
Y32

a33_
Y33

X30

S31

X32

1*30

(hb0100(bbOi,[1)0121)
U

1) UU (2-1.1) b20 /)30

I01 0 0

X0:
U

XI

X02
U

x12

Yoo

Vol

YlO

Yll

b2l

22

b3l

32 0 0 0 0 1 0 01

Here the raised dot () signifies matrix multiplication, while the operator U just Signifies
column augmentation, that is, removing the abutting parentheses and making a wider matrix
out of the operands of the U operator.,
It should not take you long to write out equation (2.1. 1) and to see that it simply states that
xis is the i th component (i = 0, 1.2. 3) of the vector solution of the j th right-hand side (j = 0,
1, 2), the one whose coefficients are bij, i = 0. 1. 2. 3; and that the matrix of unknown
coefficients Yii is the inverse matrix of aij. In other words, the matrix solution of
[A] - [xo U x, U X2 U Y] = [bo u b, u b2 U 11

(2.1.2)

where A and Y are square matrices, the bi's and xis are column vectors, and I is the identity
matrix, simultaneously solves the linear sets
A - xo = bo

A - x, = b,

A - X2 = h2

(2.1.3)

and
AY= 1

(2.1.4)

Now it is also elementary to verify the following facts about (2.1.1):

Interchanging any two rows of A and the corresponding rows of the b's and of 1 does
not change (or scramble in any way) the solution x's and Y. Rather, it just corresponds to
writing the same set of linear equations in a different order.
Likewise, tile, solution set is unchanged and in no way scrambled if we replace any
row in A by a linear combination of itself and any other row, as long as we do the same linear
combination of the rows of the b's and 1 (which then is no longer the identity matrix, of
course).

2.1 Gauss-Jordan Elimination43


Interchan2int, any two columns of A gives the same solution set only if we simultaneously
interchange corresponding rows of the x's and of Y. In other words, this interchange
scrambles the order of the rows in the solution. If we do this, we will need to unscramble the
solution by restoring the rows to their original order.
origina
elimination uses one or more of the above operations to reduce the matrix A to the identity
matrix. When this is accomplished, the right-hand side becomes the solution set, as one sees
instantly from (2.1.2).

2.1.2 Pivoting
In "Gauss-Jordan elimination with no pivoting;' only the second operation in the above list is
used. The zeroth row is divided by the element aclo (this being a trivial linear combination of
the zeroth row with any other row zero coefficient for the other row). Then the right
amount of the zeroth row is subtracted from each other row to make all the remaining ai()*s
zero. The zeroth column of A now agrees with the identity matrix. We move to column I and
divide row I by a 11. then subtract the right amount of row I from rows Q. 2. and 3, so as to
make their entries in column I zero. Column I is now reduced to the identity form. *And so
on for columns 2 and 3. As we do these operations to A. we of course also do the
corresponding operations to the b's and to 1 (which by now no longer resembles the identity
matrix in any way').
Obviously we will run into trouble if we ever encounter a zero element on the (then current)
diagonal when we are `going to divide by the diagonal element. (The element that we divide
by- incidentally. is called the pivot element or pivot.) Not so obvious, but true, is the fact that
Gauss-Jordan elimination with no pivoting use of
L
the first or third procedures in the above list) is numerically unstable in the presence of any
roundoff error, even when a zero pivot is not encountered. You must never do Gauss-Jordan
elimination (or Gaussian elimination; see below) without pivoting!
So what is this magic pivoting? Nothing more than interchanging rows (partial pivoting) or
rows and columns (full pivoting), so as to put a particularly desirable element in the diagonal
position from which the pivot is about to be selected. Since we don't want to mess up the part
of the identity matrix that we have already built up, we can choose among elements that are
both (i) on rows below (or on) the one that is about to be normalized, and also (ii) on columns
to the right (or on) the column we are about to eliminate. Partial pivoting is easier than full
pivoting, because we don't have to keep track of the permutation of the solution vector.
Partial pivoting makes available as pivots only the elements already in the correct column. It
turns out that partial pivoting is "almost" as good as full pivoting, in a sense that can be made
mathematically precise, but which need not concern us here (for discussion and references,
see [11). To show you both variants, we do full pivoting in the routine in this section and
partial pivoting in 2.3.
We have to state how to recognize a particularly desirable pivot when we see one. The answer
to this is not completely known theoretically. It is known, both theoretically and in practice,
that simply picking the largest (in magnitude) available element as the pivot is a very
ve, y good choice. A curiosity of this procedure, however, is that the choice of pivot will
depend on the original scaling of the equations. If we take the third linear equation in our
original set and multiply it by a factor of a million, it is almost gbaranteed that it will
contribute the first pivot; yet the underlying solution
gaussj.h

44

Chapter 2. Solution of Linear Algebraic Equations

of the equations is not changed by this multiplication! One therefore sometimes sees routines
which choose as pivot that element which would have been largest if the original equations
had all been scaled to have their largest coefficient normalized to unity. This is called implicit
pivoting. There is some extra bookkeeping to keep track of the scale factors by which the
rows would have been multiplied. (The routines in 2.3 include implicit pivoting, but the
routine in this section does not.)
Finally, let us consider the storage requirements of the method. With a little reflection you
will see that at every stage of the algorithm, either an element of A is predictably a one or
zero (if it is already in a part of the matrix that has been reduced to identity form) or else the
exactly corresponding element of the matrix that started as 1 is predictably a one or zero (if
its mate in A has not been reduced to the identity form). Therefore the matrix I does not have
to exist as separate storage: The matrix inverse of A is gradually built up in A as the original
A is destroyed. Likewise, the solution vectors x can gradually replace the right-hand side
vectors b and share the same storage, since after each column in A is reduced, the
corresponding row entry in the b's is never again used.
Here is a routine that does Gauss-Jordan elimination with full pivoting, replacing its input
matrices by the desired answers. Immediately following is an overloaded version for use
when there are no right-hand sides, i.e., when you want only the matrix inverse.
void aaussj(MatDoub_10 &a, 14atDoubM &b)
Linear equation solution by Gauss-Jordan elimination, equation (2.1.1) above. The input
matrix is a[0. n-11 [0. n-11. b[O. -n-1] (0. m-1) is input containing the m right-hand side
vectors. On output, a is replaced by its matrix inverse, and b is replaced by the corresponding
set of solution vectors.
Int i,icol,irow,j,k,1,11,n=a.nrowso,m=b.ncolso;
Doub big,dum,pivinv;
VecInt indxc(n),indxr(n),ipiv(n); These integer arrays are used for bookkeeping on for (j=0;
j<n; j++) ipiv[j]=0; the pivoting.
for (i=O;i<n;i++)
big=0.0;

This is the main loop over the columns to be

reduced.

for (j=O;j<n;j++)

This is the outer loop of the search for a pivot

if (ipiv[j] != 1)element.
for (k=O;k<n;k++)
if (ipiv[k] == 0) {

if (abs(a[j]rk1) >= big) {


big=abs(a[j][k]);
irow=j;
icol=k;
++(ipiv[icol]);
We now have 'he pivot element, so we interchange rows, if needed, to put the pivot element
on the diagonal. The columns are not physically interchanged, only relabeled: indxc[i], the
colum. of the (i + I)th pivot element, is the (i + 1)th column that is reduced, while indxr[i] is
the row in which that pivot element was originally located. If indxr[i] 0 indxc[i], there is an
implied column interchange. With this form of bookkeeping, the solution b's will end up in
the correct order, and the inverse matrix will be sr
,,rambled by columns.
if (irow"'.!= icol) {
for (1=0;!<n;1++) SWAP(a[irow][1],a[icol](1]); for (1=0;1<m;l++) SWAP(b[irow](11,b[icol]
[1]); I
indxr[i]=jrow; We are now ready to divide the pivot row by the pivot element, located at irow
and icol.
2.1 Gauss-Jordan Elimination45
if (a[i_ol] [11-- ;i]
P

ri%

CG r o.:

g aij s s

S i n gi 1 1 a r

ai

a i -,) 1 1 c o 1
for ("=fj; I<ri 1++) a[ico!]Lll pivinv; for '1-0;l<m; [++) b[icolj[111 pivinv;
for '11-0;11<n'll++)

Next, we reduce the rows..

if !11 I- "-Col) I

...except for the pivot one, of course. dum=a[l1][ico1],

arlli
fox (1=0;1<nll++) a[11] [1] a[icol] [1]*durr,; for (1=0;1<m;l++) b[11][1] b[icol]
[l]*dw.ri; I
This is the end of the main loop over columns of the reduction. It only remains to
unscramble the solution in view of the column interchanges. We do this by interchanging
pairs of columns in the reverse order that the permutation was built up.
o1- (1=n-';1>=0;1--) f

if (ind.-r[1] indxc[l])
for (k=O;k<,i;k++)
And .we are done.
Voi,i qaussj(MatDoub_10 &a)
Overloaded version with no right-hand sides. Replaces a by its inverse.
a DL

Dummy vector with zero columns-ffaussj(a,b);

2.1.3 Row versus Column Elimination Strategies


The above discussion can be amplified by a modest amount of formalism. Row operations
on a matrix A correspond to pre- (that is, left-) multiplication by some simple matrix R. For
example, the matrix R with components
1 if i = j and i 0 2.4 1 if i =2.j =4 Rij =
I if i =4, j =2
0 otherwise
effects the interchange of rows 2 and 4. Gauss-Jordan elimination by row operations alone
(including the possibility of partial pivoting) consists of a series of such left- multi pl ications,
(including
yielding successively
A-xb
R2 - RI - Ro - A) - X =...R2 R I - Ro - b
(1).x =...R2 RI - Ro - b
X

... R2 - Rl - Ro - b

The key point is that since the R's build from right to left, the right-hand side is simply
transformed at each stage from one vector to another.
Column operations, 0"a the other hand, correspond to post-, or right-, muitiplications by
simple matrices, call them C. The matrix in equation (2.1.5), if right-multiplied onto a matrix
A, will interchange columns 2 and 4 of A. Elimination by column operations involves
(conceptually) inserting a column operator, and also its inverse, between the matrix A and the
(2.1.5)
(2.1.6)
2.1 Gauss-Jordan Eliminasi -11

Gill. RE .. Murray. W., dan Wright, M.H. 1991, Numerik Aljabar Linear dan Optimasi, vol. (.
Redwood City CA: Addison-Wesley) 1.
Stoer, J., dan Bulirsch. R. 2002, Pengantar Analisis Numerik, 3rd ed. (New York: Springer),
Bab 4.
Ueberhuber, CW 1997, Numerik Komputasi: Metode, Software, dan Analisis, 2 jilid. (Berlin:
Springer), Bab 13.
Coleman, TF, dan Van Loan, C. 1988, Handbook untuk Matrix Perhitungan (Philadelphia:
S.1-AM).
Forsythe, GE, dan Molex, CB 1967, Komputer Solusi dari Linear Aljabar Sistem (Cliffs
Engle-kayu, NJ: Prentice-Hall).
Wilkinson, JH, dan Reinsch, C. 1971, Aljabar Linear, vol. II dari Handbook untuk Automatic
Computation (New York: Springer).
Westlake, JR 1968, A Handbook of Numerical Matrix Inversi dan Solusi Persamaan Linear
(New York: Wiley).
Johnson, LW, dan Riess, RD 1982, Analisis Numerik, 2nd ed. (Reading, NIA:
AddisonWesley), Bab 2.
Ralston, A., dan Rabinowitz, R 1978, A Course Pertama di Numerik Analisis, 2nd ed .;
dicetak ulang 2001 (New York: Dover), Bab 9.
2.1 Gauss-Jordan Eliminasi
Eliminasi Gauss-Jordan mungkin adalah cara Anda belajar untuk memecahkan equa-tions
linear di sekolah tinggi. (Anda mungkin telah belajar sebagai "eliminasi Gauss -. Tapi,
tegasnya, istilah yang merujuk pada teknik yang agak berbeda dibahas dalam 2.2.) Ide
dasarnya adalah untuk menambah atau mengurangi kombinasi linear dari theuntil setiap
Saya iven persamaan
persamaan hanya berisi satu dari yang tidak diketahui, sehingga memberikan solusi segera.
Anda juga mungkin telah belajar untuk menggunakan teknik yang sama untuk menghitung
invers matriks.
Untuk memecahkan set persamaan linear, eliminasi Gauss-Jordan memproduksi baik solusi
dari persamaan untuk satu atau lebih kanan sisi vektor b, dan juga kebalikan matriks A- '.
Namun, kekurangan utamanya adalah (i) bahwa ia memerlukan semua sisi kanan untuk
disimpan dan dimanipulasi pada saat yang sama, dan (ii) bahwa ketika matriks inverse tidak
diinginkan. Gauss-Jordan adalah tiga kali lebih lambat dari teknik alternatif terbaik untuk
memecahkan satu set linear (2.3). Kekuatan utama metode ini adalah bahwa hal itu stabil
seperti metode langsung lainnya, bahkan mungkin sedikit lebih stabil saat berputar penuh
digunakan (lihat 2.1.2).

Untuk pembalik matriks, eliminasi Gauss-Jordan adalah tentang seefisien metode langsung
lainnya. Kami tahu tidak ada alasan untuk tidak menggunakannya dalam aplikasi ini jika
Anda yakin bahwa kebalikan matriks adalah apa yang Anda inginkan.
Anda mungkin bertanya-tanya tentang kekurangan (i) di atas: Jika kita mendapatkan matriks
di-ayat pula, tidak bisa kita kemudian membiarkannya berkembang biak sisi kanan baru
untuk mendapatkan solusi tambahan '? Ini tidak bekerja, tetapi memberikan jawaban yang
sangat rentan terhadap kesalahan roundoff dan tidak sebagus jika vektor baru telah disertakan
dengan set kanan vektor sisi ih contoh pertama.
Jadi, eliminasi Gauss-Jordan tidak boleh metode Anda pilihan pertama untuk memecahkan
persamaan linear. Metode dekomposisi dalam 2.3 lebih baik. Mengapa-kita tidak membahas
Gauss-Jordan sama sekali? Karena itu sangat mudah, padat seperti batu, dan tempat yang
baik bagi kita untuk memperkenalkan konsep penting dari berputar yang juga akan
~f
42 Bab 2. Solusi dari Linear Aljabar Persamaan
menjadi penting bagi metode yang dijelaskan kemudian. Urutan yang sebenarnya dari operasi
,,, dilakukan di eliminasi Gauss-Jordan ini sangat erat kaitannya dengan yang dilakukan oleh
rutinitas dalam dua bagian berikutnya.
2.1.1 Penghapusan pada Matriks Kolom-Augmented
Untuk kejelasan, dan untuk menghindari menulis elips tak berujung (...) kita akan menuliskan
persamaan hanya untuk kasus empat persamaan dan empat yang tidak diketahui, dan dengan
tiga vektor sisi kanan berbeda yang dikenal di muka. Anda dapat menulis matriks yang lebih
besar dan memperluas persamaan untuk kasus N x N matriks, dengan M set vektor sisi kanan,
dalam mode benar-benar analog. Rutinitas diimplementasikan bawah di 2.1.2, tentu saja,
umum.
Mempertimbangkan persamaan matriks linier
AOO aol a02 A03 X0 X0: X02 Yoo Vol Y02 Y03
alo semua A12 A13 X10 U XI U x12 U YlO yll Y12 Y13
a2o A21 a22 A23 X20 X21 X22 YO) o Y21 Y22 Y23
_a30 A31 A32 a33_ X30 S31 X32 1 * 30 Y31 Y32 Y33
(hb0100 (bbOi, [1) 0121) I01 0 0
U 1) UU (2-1,1) B20 /) 30
b2l 22
b3l 32 0 0 0 0 1 0 01

Berikut mengangkat dot () menandakan perkalian matriks, sedangkan operator U hanya


Signifies kolom augmentation, yang, menghapus tanda kurung berbatasan dan membuat
matriks yang lebih luas dari operan dari operator U.,
Seharusnya tidak membawa Anda lama untuk menulis persamaan (2.1. 1) dan melihat bahwa
itu hanya menyatakan bahwa xis adalah i komponen (i = 0, 1,2. 3) dari solusi vektor j th sisi
kanan (j = 0, 1, 2), satu yang koefisien Bij, i = 0 1. 2. 3; dan bahwa matriks koefisien yang
tidak diketahui Yii adalah matriks kebalikan dari aij. Dengan kata lain, solusi matriks
[A] - [xo U x, U X2 UY] = [bo ub, u B2 U 11 (2.1.2)
dimana A dan Y adalah matriks persegi, bi dan xis adalah vektor kolom, dan saya adalah
matriks identitas, sekaligus memecahkan set linear
A - xo = bo A - x, = b, A - X2 = h2 (2.1.3)
dan
Sebuah Y = 1 (2.1.4)
Sekarang juga SD untuk memverifikasi fakta-fakta berikut tentang (2.1.1):
Interchanging setiap dua baris A dan baris yang sesuai dari b dan dari 1 tidak berubah (atau
berebut dengan cara apapun) solusi x dan Y. Sebaliknya, itu hanya sesuai dengan menulis set
yang sama persamaan linear dalam urutan yang berbeda . Demikian juga, tile, solusi set tidak berubah dan tidak ada cara bergegas jika kita mengganti
baris A dengan kombinasi linear dari dirinya sendiri dan setiap baris lainnya, selama kita
melakukan kombinasi linear yang sama dari baris dari b dan 1 ( yang kemudian tidak lagi
matriks identitas, tentu saja).

2.1 Gauss-Jordan Eliminasi 43


Interchan2int, setiap dua kolom A memberikan solusi yang sama ditetapkan hanya jika kita
secara bersamaan pertukaran baris yang sesuai dari x dan Y. Dengan kata lain, pertukaran ini
mengacak urutan baris dalam larutan. Jika kita melakukan ini, kita perlu menguraikan solusi
dengan mengembalikan baris ke urutan asli mereka.
origina
eliminasi menggunakan satu atau lebih dari operasi di atas untuk mengurangi matriks A
dengan matriks identitas. Bila ini dilakukan, sisi kanan menjadi himpunan solusi, sebagai
salah satu melihat langsung dari (2.1.2).
2.1.2 Berputar

Dalam "Gauss-Jordan eliminasi tanpa berputar; ' . hanya operasi kedua dalam
daftar di atas digunakan The zeroth baris dibagi dengan aclo elemen (ini
menjadi kombinasi linear sepele baris ke nol dengan baris lain - koefisien nol
untuk baris lainnya) Kemudian jumlah yang tepat dari. zeroth baris dikurangi
dari setiap baris lain untuk membuat semua ai tersisa () * s nol. The zeroth
kolom A sekarang setuju dengan matriks identitas. Kami pindah ke kolom I dan
membagi baris saya dengan 11. kemudian mengurangi jumlah yang tepat baris
saya dari baris Q. 2. dan 3, sehingga membuat entri dalam kolom saya nol.
Kolom Aku sekarang dikurangi menjadi bentuk identitas. * Dan seterusnya
untuk kolom 2 dan 3. Seperti yang kita lakukan operasi ini untuk A . kita tentu
juga melakukan operasi sesuai dengan b dan untuk 1 (yang sekarang tidak lagi
menyerupai matriks identitas dengan cara apapun ').
Jelas kita akan mengalami kesulitan jika kita pernah menemukan elemen nol
pada (kemudian saat) diagonal ketika kita `akan membagi dengan elemen
diagonal. (Unsur yang kita membagi sampingan kebetulan. Disebut elemen
poros atau pivot.) Tidak begitu jelas, tapi benar, adalah kenyataan bahwa
eliminasi Gauss-Jordan dengan tidak menggunakan berputar dari
L
prosedur pertama atau ketiga dalam daftar di atas) adalah numerik yang tidak stabil dengan
adanya kesalahan roundoff, bahkan ketika poros nol tidak ditemui. Anda tidak harus
melakukan eliminasi Gauss-Jordan (atau eliminasi Gauss; lihat di bawah) tanpa berputar!
Jadi apa berputar sihir ini? Tidak ada yang lebih dari interchanging baris (berputar parsial)
atau baris dan kolom (berputar penuh), sehingga untuk menempatkan elemen sangat
diinginkan dalam posisi diagonal dari mana poros akan segera dipilih. Karena kita tidak ingin
mengacaukan bagian dari matriks identitas bahwa kita telah membangun, kita bisa memilih di
antara unsur-unsur yang baik (i) pada baris bawah (atau di) salah satu yang akan menjadi
normal, dan juga (ii) pada kolom ke kanan (atau) kolom kita akan menghilangkan. Berputar
parsial lebih mudah daripada berputar penuh, karena kita tidak harus melacak permutasi dari
vektor solusi. Berputar parsial membuat tersedia sebagai pivot hanya elemen yang sudah
dalam kolom yang benar. Ternyata berputar parsial adalah "hampir" sebaik berputar penuh,
dalam arti yang dapat dibuat secara matematis tepat, tetapi yang tidak perlu menjadi perhatian
kita di sini (untuk diskusi dan referensi, lihat [11). Untuk menunjukkan kedua varian, kita
lakukan berputar penuh dalam rutinitas di bagian ini dan berputar parsial di 2.3.
Kita harus menyatakan bagaimana mengenali poros sangat diinginkan ketika kita melihat
satu. Jawaban untuk ini tidak sepenuhnya diketahui secara teoritis. Hal ini diketahui, baik
secara teori maupun dalam praktek, yang hanya memilih terbesar (besarnya) elemen tersedia
sebagai poros adalah sangat

ve, pilihan yang baik y. Sebuah rasa ingin tahu prosedur ini, bagaimanapun, adalah bahwa
pilihan poros akan tergantung pada skala asli dari persamaan. Jika kita mengambil persamaan
linear ketiga di set asli dan kalikan dengan faktor satu juta, hampir gbaranteed bahwa itu akan
memberikan kontribusi poros pertama; namun solusi yang mendasari
gaussj.h
44 Bab 2. Solusi dari Linear Aljabar Persamaan
persamaan tidak berubah dengan perkalian ini! Satu Oleh karena itu kadang-kadang melihat
rutinitas yang memilih sebagai poros elemen yang akan menjadi terbesar jika persamaan asli
semua telah ditingkatkan untuk memiliki koefisien terbesar mereka dinormalisasi ke
kesatuan. Ini disebut berputar implisit. Ada beberapa pembukuan ekstra untuk melacak faktor
skala dimana baris akan telah dikalikan. (Rutinitas di 2.3 termasuk berputar implisit, tetapi
rutin di bagian ini tidak.)
Akhirnya, marilah kita mempertimbangkan persyaratan penyimpanan metode ini. Dengan
sedikit refleksi Anda akan melihat bahwa pada setiap tahap algoritma, baik unsur A adalah
diduga satu atau nol (jika sudah di bagian matriks yang telah direduksi menjadi bentuk
identitas) atau persis sesuai elemen dari matriks yang dimulai sebagai 1 adalah diduga satu
atau nol (jika pasangannya A belum dikurangi menjadi bentuk identitas). Oleh karena itu
matriks saya tidak harus ada sebagai penyimpanan terpisah: Matriks invers A secara bertahap
dibangun di A sebagai A asli hancur. Demikian juga, vektor solusi x secara bertahap dapat
menggantikan kanan vektor sisi b dan berbagi penyimpanan yang sama, karena setelah setiap
kolom A berkurang, entri baris yang sesuai di b tidak pernah lagi digunakan.
Berikut ini adalah rutin yang tidak eliminasi Gauss-Jordan dengan berputar penuh, replacing
matriks input dengan jawaban yang diinginkan. Segera setelah adalah versi overloaded
untuk digunakan ketika tidak ada sisi kanan, yaitu, ketika Anda ingin hanya kebalikan
matriks.
kekosongan aaussj (MatDoub_10 & a, 14atDoubM & b)
Persamaan linier solusi oleh eliminasi Gauss-Jordan, persamaan (2.1.1) di atas. Input matriks
adalah [0. n-11 [0. n-11. b [O. -n-1] (0 m-1) adalah masukan yang berisi vektor sisi m kanan.
Pada output, yang diganti dengan inverse matriks, dan b diganti dengan set yang sesuai
vektor solusi.
Int i, icol, irow, j, k, 1,11, n = a.nrowso, m = b.ncolso;
Doub besar, dum, pivinv;
VecInt indxc (n), indxr (n), ipiv (n); Array bilangan bulat ini digunakan untuk pembukuan
selama (j = 0; j <n; j ++) ipiv [j] = 0; yang berputar.
untuk (i = O; i <n; i ++) ini adalah loop utama atas kolom menjadi
besar = 0,0; dikurangi.

untuk (j = O; j <n; j ++) ini adalah lingkaran luar pencarian untuk poros
jika (ipiv [j]! = 1) elemen.
untuk (k = O; k <n; k ++)
jika (ipiv [k] == 0) {
jika (abs (a [j] RK1)> = besar) {
besar = abs (a [j] [k]);
irow = j;
icol = k;
++ (ipiv [icol]);
Kami sekarang memiliki 'dia poros elemen, jadi kami pertukaran baris, jika diperlukan, untuk
menempatkan elemen poros pada diagonal. Kolom tidak secara fisik dipertukarkan, hanya
dilabel ulang: indxc [i], Colum yang . dari (i + I) th elemen poros, adalah (i + 1) th kolom
yang berkurang, sementara indxr [i] adalah baris dimana elemen poros awalnya berada. Jika
indxr [i] 0 indxc [i], ada kolom pertukaran tersirat. Dengan bentuk pembukuan, solusi b akan
berakhir dalam urutan yang benar, dan matriks inverse akan sr
,, mengoceh oleh kolom.
jika (irow "'.! = icol) {
untuk (1 = 0;! <n; 1 ++) SWAP (a [irow] [1], sebuah [icol] (1]); for (1 = 0; 1 <m; l ++) SWAP
(b [irow ] (11, b [icol] [1]); Saya
indxr [i] = jrow; Kami sekarang siap untuk membagi baris poros oleh elemen poros, terletak
di irow dan icol.
2.1 Gauss-Jordan Eliminasi 45
jika (a [i_ol] [11--; i] CG r o g .: aij ss S di gi 1 1 ar
P ri% i
i -,) 1 1 c o 1
untuk ("= fj, saya <ri 1 ++) a [ico!] BMPK - pivinv; untuk '1-0; l <m; [++) b [icolj [111 pivinv;
(2.1.6)

Das könnte Ihnen auch gefallen