½u©Ê¥N¼Æ°ÝÃD¡G¼Æ¾Ç°ÝÃD­åªR¡B°ª´µ¡Ð¦õ¤¦®ø¥hªk

½Òµ{­nÂI´£¥Ü

 

¯}ÃD¡G½u©Ê¥N¼Æ¤èµ{¦¡ªº¸Ñ

¤èµ{¦¡»P¨ç¼Æ¦³¤°»ò¤£¦P¡H

¤°»ò¬O¨D¸Ñ¡H¡]§â¥¼ª¾¼ÆÅܦ¨¤wª¾ªº¹Lµ{¡^

¤°»ò¬O¸Ñ¡H¡]¯à²Å¦X­ì¤èµ{¦¡¤§¥¼ª¾¼Æªº¼Æ­È¡B¨ç¼Æ¡A©ÎÃö«Y¦¡¡^

¤°»ò¬O¥N¼Æ¤èµ{¦¡¡H¡]¦³§O©ó·L¤À¤èµ{¦¡¡^

¤èµ{³o­ÓÃã¬O«ç»ò¨Óªº¡H

¤°»ò¬O½u©Ê¡H

¤°»ò¬O½u©Ê¥N¼Æ¡H

¤°»ò¬O½u©Ê²Õ¦X¡H

¤@­Ó½u©Ê¤èµ{²Õªº¨ä¤¤¤@±ø¤èµ{¦¡¡A¦b´X¦ó¤W¨ã¦³¤°»ò¼Ëªº·N¸q©Î¹Ï¹³¡H¡]°ªºû«×ªÅ¶¡ªºª½½u¤èµ{¦¡¡^

 

½u©Ê¥N¼Æ¤èµ{¦¡¡]²Õ¡^ªº¤@¯ë§Î¦¡¬O¤°»ò¡H

½u©Ê¥N¼Æ¤èµ{¦¡

¨ä¤¤©Ò¦³ aij ¤Î bi ³£¬O¤vª¾¡A©Ò¦³ xj ³£¬O¥¼ª¾¡A­Y¤£¬O¦p¦¹¡A´N¤£¬O½u©Ê¥N¼Æ¤èµ{¦¡¤F¡C

­Y¥¼ª¾¼Æªº­Ó¼Æ»P¤èµ{¦¡ªº­Ó¼Æ¬Û¦P¡A§Y N = M¡A«h¤W¦¡¤èµ{²Õ¦³¥i¯à¥i¥H¦³°ß¤@¸Ñ¡C¸ÑªR¤W¦Ó¨¥¡A¦pªG¬Y¤@±ø¤èµ{¦¡¬O¨ä¥L¤èµ{¦¡ªº½u©Ê²Õ¦X¡A´N§Î¦¨¤F¦æ²¨Ö¡C¡]¤°»ò¬O²¨Ö¡^©Î©Ò¦³¤èµ{¦¡¦@¦P§t¦³¬Y´X­ÓÅܼƪº¯S©w²Õ¦X¤è¦¡¡A¦p x5 ©Ò¦³¨t¼Æ»P x3 »P x4 ¨t¼Æ©Ò¦³§e½u©Ê²Õ¦XÃö«Y¡A«h¦¨¦C²¨Ö¡C¡]¦b N = M ªº±¡ªp¤U¡A¦³¦æ²¨Ö´N¤@©w¦³¦C²¨Ö¡A¨Ã¥B§Ú­ÌºÙ¦¹¤èµ{¦¡¬°©_²§ªº¡]singular¡^¡C

 

½u©Ê¥N¼Æ¤èµ{¦¡¡]²Õ¡^¨ä¸Ñªº¤£ÅÜ©Ê

½u©Ê¥N¼Æ¤èµ{¦¡ªº¸Ñ¦³¤@¨Ç¦³½ìªº¤£ÅÜ©Ê¡A¤]»¡¬O»¡¡A­ì¤èµ{²Õ§@¬Y¨Ç¥~Æ[©Î§Î¦¡¤Wªº§ïÅÜ¡A¹ï¨ä¸Ñ¨ÃµL¼vÅT¡C

¥H¤G¤¸¤@¦¸¤èµ{²Õ

ax + by = c

dx + ey = f

¬°¨Ò¡A·Q·Q¬Ý«ç¼ËªºÃD¥ØÅܤƤ´·|Åý¨ä x¡By ªº¸Ñ«O«ù¤£ÅÜ¡H

¦æ¹ï½Õ

dx + ey = f

ax + by = c

¥[ªk¥»¨Ó´N¥i¥H¥æ´«

by + ax = c

ey + dx = f

¦C¥æ´«¡]x »P y ªº¨¤¦â·|¹ï½Õ¡^

bx' + ay' = c

ex' + dy' = f

¥ô¤@¦¡¾ã­Ó¡]µ¥¸¹¨âÃä¡^¦P­¼¬Y«Y¼Æ

k(ax) + k(by) = k(c)

dx + ey = f

µ¥¸¹¨âÃä¥[´î¦P¶q

(a-d)x + (b-e)y = c-f

dx + ey = f

 

 

Gauss-Jordan ®ø¥hªk

¤j®a¦b¤¤¾Ç®É¦³¾Ç¹L °ª´µ®ø¥hªk¨D¤Ï¯x°}¡A§A­Ì¥Îªºª«¼Æ±Ð¬ì®Ñ­è¦n¤]¦³¡A§Ú±½´y¤U¨Óµ¹¤j®a½Æ²ß¤§¥Î Arfken page¡C

Gauss-Jordan Inversion 1
Gauss-Jordan Inversion 2

¬°¤°»ò³o¼Ë°µ´N¤U¥h¡A¥kÃ䪺´N¬O¤Ï¯x°}¡H

°²³]§Ú­Ì¤£ª¾¹D¤Ï¯x°} A-1 ¬O«ç¼Ë¡A¼g§@ Y¡]¥Î Y ¬O¨ú¨ä±`§@¬°ÅܼƤ§¥Îªº·N«ä¡^¡A´N¦³ A Y = I¡A¦p¦¹¡A¦b Y ªº¸Ñ¤£Åܪº±¡§Î¤§¤U¡A¤@¸ô¾ã²z¨ì A' Y  = I' -> A'' Y = I'' -> ... -> ª½¨ì I Y = [¬Y¯x°}]¡A¦Ó Y ¸Ñªº¥»½è¨Ì¬Y­ì¥»ªº©w¸q¬O A-1¡A¦]¦¹¸Ó [¬Y¯x°}] ´N¬O A ªº¤Ï¯x°}¤F¡C

¨D A ªº¤Ï¯x°}¦³¤°»ò¥Î¡H¤£¬O­n¸Ñ A x = b ¶Ü¡H

¦³¤F A ªº¤Ï¯x°}¡A§Ú­Ìª¾¹D A-1 A x = A-1 b¡A¦]¦¹´Nª½±µ¦³ x = A-1 b ¦Ó§â¸Ñºâ¥X¨Ó¡C

 

¦bNumerical Recipe ½Ò¤å¤¤¡A§@ªÌ¯S§O¥X¤TºØ§ï³y²¤Æ­ì¤èµ{¦¡¡]¦Ó¨ä¸Ñ¤´¤£ÅÜ¡^ªº°Ê§@¡A¨ä¤¤²Ä¤GÂI´N¬O¾Þ§@°ª´µ¦õ¤¦®ø¥hªkªº°ò¥»¨Ì¾Ú¡A½Ð¤j®aª`·N¤@¤U¡C

 

Column-Augmented ªí¥Üªk

¦Ò¼{¥H¤U¨â­Ó½u©Ê¥N¼Æ¤èµ{²Õ Ax = b¡B Ay = c ¨Ì·Ó¯x°}§@¥Î¦b¦C¦V¶qªº¹Bºâ³W«h¡A¥¦§¹¥þ¥i¥H¦X¨Ö¦¨¬° A[x y] = [b c] ¦Ó§¹¥þ¤£¼vÅT [x] ¤Î [y] ¦C¦V¶qªº¸Ñ¡C

¨ì¦¹§Ú­Ì¥i¥H²z¸Ñ¡A¥u­n¯à§â¤W­z°Ê§@¼g¦¨µ{¦¡¡A°t¦X Column-Augmented ¸ê®Æ±Æ¦C¤è¦¡¡A§Ú­Ì´N¥i¥H¦³¤@­Ó¨D¸Ñ Ax = b ¤§ x ¥H¤Î AY = I ¤§ Y ªº¦Û°Ê¤Æ¤èªk¤F¡C

 

Pivoting

¬°¤FÅý¼Æ­È¹Bºâªº¹Lµ{¹F¨ì³Ì°ªªººë½T«×¤Îí©w©Ê¡A§Ú­Ì¾¨¥i¯à­n§â³Ì¤jªº¤¸¯À½Õ¨ì¹ï¨¤½u¤Wªº¦ì¸m¡A­Y¬O§@¦C¹ï½Õ¡A«h¸Ñ¤£¨ü¼vÅT¡F­Y§@¦æ¹ï½Õ¡A«h¸Ñ¤´¤£ÅÜ¡A¥u®t¯A¤Î¨è¹ï½Õ¦C¨º¨â­Ó¹ïÀ³ªº«Ý¨D¸Ñ¥¼ª¾Åܼƪº¨¤¦â­n¹ï½Õ¡]¨Ò¦p¡A²Ä¤T¦C»P²Ä¤­¦C¹ï½Õ¡A«h x3 »P x5 ªº¨¤¦â­n¤¬´«¡^¡C¦b¦³¥]§t¦C¹ï½Õ¥\¯àªº Gauss-Jordan µ{¦¡¤¤¡Aµ{¦¡·|°lÂÜ°O¿ý©Òµo¥Í¹Lªº¨¤¦â¤¬´«¦Ó¦b³Ì«á¦L¥Xµª®×«e§â¥¦­Ì½Õ´«¦^¨Ó¡A½Ò¥»¤¤ªºµ{¦¡´N¬O³o¼Ë¡C

 

°Æµ{¦¡¤§¨Ï¥Î

¥Ñ©ó³o¬O¤j®a²Ä¤@¦¸¾Ç²ß¨Ï¥Î Numerical Recipe ¤Wªºµ{¦¡¡A§Ú§â¨Ï¥Îªº¨BÆJ»P­nÂIÁ¿¥J²Ó¤@ÂI¡C

­º¥ý¡A¬Ý²M·¡½Ò¤å¤¤°Æµ{¦¡ùتº»¡©ú¤å¦r±Ô­z¡]¹q¤lÀɨS¦³¡A½Ò¤å¤~¦³¡^¡A¹³¬OÂŦ⪺³o¤@¶ô¡G

SUBROUTINE gaussj(a,n,np,b,m,mp)
INTEGER m,mp,n,np,NMAX
REAL a(np,np),b(np,mp)
PARAMETER (NMAX=50)
Linear equation solution by Gauss-Jordan elimination, equation (2.1.1) above. a(1:n,1:n) is an input matrix stored in an array of physical dimensions np by np. b(1:n,1:m) is an input matrix containing the m right-hand side vectors, stored in an array of physical dimensions np by mp. On output, a(1:n,1:n) is replaced by its matrix inverse, and b(1:n,1:m) is replaced by the corresponding set of solution vectors.Parameter: NMAX is the largest anticipated value of n.
INTEGER i,icol,irow,j,k,l,ll,indxc(NMAX),indxr(NMAX),

³oùØ­±´y­z¤F§@¬°¿é¤J®É¡Aa¡Bb °}¦C¦U¬O¤°»ò¥H¤Î¥¦­Ìªº¤j¤p n¡Bm¡Bnp¡Bmp µ¥¡C ¤]´£¨ì¤F§@¬°¿é¥X®É¡A°}¦C a¡Bb ¤S¦U¦Û¨ã¦³¤°»ò·N¸q¡C

¨ä¦¸¡A§Ú­Ì¦Û¤v­n¼g¤@­Ó¥Dµ{¦¡¨Ó¥s¥Î gaussj °Æµ{¦¡¡Cª`·N gaussj ¤¤¦³«Å§i a(np,np)¡Bb(np,mp) ·|¥Î¨ì¾ã¼Æ­È np ¤Î mp ¡A§Ú­Ì·íµM¤£·|§Æ±æ¨C¦¸­n¥Î gaussj ´N¥h§ï¨ì¥¦ªº¤º®e¡A³o´N¥²¶·¥Ñ¦b¥Dµ{¦¡´N§@¦n«Å§i¡AÅý°Æµ{¦¡¨ÓÄ~©Ó¡C«h§Ú­Ì¦b¥Dµ{¦¡¤¤ªº§@ªk¦p¤U¡]¥H a ¬O 3x3¡Bb ¬O column vector 3x1 ¬°¨Ò¡^¡G

program gauss_main
real a(3,3), b(3,1)
integer n, np, m, mp, i
parameter (np=3, mp=1)

©Î¬O¡Aµy·L¦A°ª¬ñ¤@ÂI

program gauss_main
integer n, np, m, mp, i
parameter (np=3, mp=1)
real a(np,np), b(np,mp)

np¡Bmp ¥²¶·¥ý«Å§i¦¨¾ã¼Æ¡A³o¬O¥»¨Ó´N­n°µªº¡C¤@¥¹¨Ï¥Î¤F parameter «ü¥O§â³o¨Ç¾ã¼ÆÅܼƪº¼Æ¥[¥H«ü©w¡]¦b¾ã­Óµ{¦¡¤¤¥¦­Ìªº­È³£¤£·|¦A§ïÅÜ¡A¥iµø¬°¬O¤@­Ó±`¼Æ¦Ó¤£¦A¬OÅܼơ^¡A§Ú­Ì´N¥i¥H¥Î¨Ó«Å§i°}¦C¡A³o¬O¦]¬°½sĶ¾¹¤w©ú½T¦aª¾¹D np¡Bmp ªº­È¬O¦h¤Ö¤F¡C
³o¼Ë¡A¤£¦ý¥Dµ{¦¡¤¤ªº«Å§i§¹¦¨¡A¤]¥i¥HÅý°Æµ{¦¡ gaussj ªº«Å§i§´·í¡A§Ú­Ì¦b¦¹À˵ø¤@ °Æµ{¦¡ gaussj ¦b«Å§i a¡Bb ªº³¡¤À¡G

SUBROUTINE gaussj(a,n,np,b,m,mp)
INTEGER m,mp,n,np,NMAX
REAL a(np,np),b(np,mp)
PARAMETER (NMAX=50)
INTEGER i,icol,irow,j,k,l,ll,indxc(NMAX),indxr(NMAX),ipiv(NMAX)
REAL big,dum,pivinv

§A¬Ý¡A¥¦¬Oª½±µ«Å§i REAL a(np,np),b(np,mp)¡A³o¼Ë´N¥i¥H¤F¡A§Ú­Ì§¹¥þ¤£¥²§ó§ï gaussj ªº¤º®e¡C

¤@­Ó²©öªº¡A¯à©I¥s°Æµ{¦¡ gaussj ªº¥Dµ{¦¡¡]°²³] a ¬O 3x3¡Bb ¬O 3x1¡^¦p¤U¡G

program gauss_main

integer n, np, m, mp, i
parameter (np=3, mp=1)
real a(np,np), b(np,mp)

n=3
m=1

open (unit=20, file='a.dat')
do i=1,3
read (20,*) a(i,1), a(i,2), a(i,3)
enddo
close(20)

open (unit=20, file='b.dat')
do i=1,3
read (20,*) b(i,1)
enddo
close(20)

call gaussj(a,n,np,b,m,mp)

write(*,*) 'The inverse matrix is :'
do i=1,3
write (*,*) a(i,1), a(i,2), a(i,3)
enddo

write (*,*)

write (*,*) 'and the solution matrix is :'
do i=1,3
write (*,*) b(i,1)
enddo

end

¤@­Ó¥\¯à¸û§¹¾ã¡A¯à³B²z¤£¦P¯x°}¤j¤p°ÝÃDªº¥Dµ{¦¡½d¨Ò¦p¤U¡A­«ÂI§Ú¥H±m¦â¼Ð¥X¡G

program gauss_main2

integer n, np, m, mp, i
parameter (np=10, mp=20)
real a(np,np), b(np,mp)
character*40 filename1, filename2

write (*,*)'Please tell me the dimension n of the matrix (n,n):'
read (*,*) n
if(n.gt.np) stop 'n can not be larger than np'

write (*,*) 'Please give the size m of the augmented b(n,m):'
read (*,*) m

if(m.gt.mp) stop 'm can not be larger than mp'

write (*,*) 'Please give the file name that contains A :'
read (*,*) filename1
write (*,*) 'Please give the file name that contains b :'
read (*,*) filename2

open (unit=20, file=filename1)
do i=1,n
read (20,*) ( a(i,j), j=1,n )
enddo
close(20)

open (unit=20, file=filename2)
do i=1,n
read (20,*) ( b(i,j), j=1,m )
enddo
close(20)

call gaussj(a,n,np,b,m,mp)

write(*,*) 'The inverse matrix is :'
do i=1,n
write (*,*) ( a(i,j), j=1,n )
enddo
write (*,*)
write (*,*) 'and the solution matrix is :'
do i=1,n
write (*,*) ( b(i,j), j=1,m )
enddo

end

 

 

³Ì«á¡A§Ú­Ì­n§â ¥D¡B°Æµ{¦¡½sĶ¨ÃÃìµ²¦b¤@°_³y¥X¥i°õ¦æÀÉ¡A³o­n¶i¦æ¥H¤Uªº°Ê§@¡G

gfortran -o my_gaussj.x gauss_main.f gaussj.f

©ÎªÌ¬O¥ý¥Î -c¡]compile only¡^±o­Ó¦Û .o ÀÉ«á¦A link ¦b¤@°_¦p¤U¡G

gfortran -c gauss_main.f
gfortran -c gaussj.f
gfortran -o my_gaussj.x gauss_main.o gaussj.o

³o¨ä¤¤·|¹J¨ìĵ§i°T®§¡A¦ý³o¬OµL®`ªº

´ú¸Õ¤]¬O«Ü­«­nªº¡Cµ{¦¡­è¼g¦n®É¡A§A¥i¥H¥Î¤@­Ó¤v¸g©Î«Ü®e©öª¾¹Dµª®×ªºÃD¥Ø¥ý§@´ú¸Õ¡A¨Ò¦p a¡Bb ¤À§O¬°¡G

1 0 0
0 2 0
0 0 4

¤Î

1
1
1

¦³¤F¤W­z¼Æ¾Ú§@¬°ÀÉ®× a.dat »P b.dat ªº¤º®e¡A©ñ¦b»P¥i°õ¦æÀÉ my_gauss.x ¦P¤@­Ó¥Ø¿ý¤U¡A¥´ ./my_gauss.x¡Aµª®×´N·|¦C¥X¨ì¿Ã¹õ¤W¤F¡C

 

¸É¥R¸ê°T

Cramer's rule ¡G¥Î©ó¨D¸Ñ Ax = b ¤§¸ÑªR¤½¦¡¡A¥Î¨ì¨D¦æ¦C¦¡­È¡Cºû°ò¦Ê¬ì¤¤ªº¤¶²Ð

¥H¤U§ó¦h¨Ó¦Ûºû°ò¦Ê¬ìªº¤¶²Ð

Systems of linear equations belong to the oldest problems in mathematics and they have many applications, such as in digital signal processing, estimation, forecasting and generally in linear programming and in the approximation of non-linear problems in numerical analysis.

Linear algebra is the branch of mathematics concerned with the study of vectors, vector spaces (also called linear spaces), linear transformations, and systems of linear equations. Vector spaces are a central theme in modern mathematics; thus, linear algebra is widely used in both abstract algebra and functional analysis. Linear algebra also has a concrete representation in analytic geometry and it is generalized in operator theory. It has extensive applications in the natural sciences and the social sciences, since nonlinear models can often be approximated by a linear model.


 

½u©Ê¥N¼Æ°ÝÃD¡G¤Ï¦V¥N¦^ªk¡]Back Substitution¡^

 

¤Ï¦V¥N¦^ªk¡]Back Substitution¡^

Åý§Ú­Ì²{¦b¨Ó¦Ò¼{¤@­Ó»P«e¤@¸`¤£¤Ó¤@¼Ëªº±¡ªp¡A°²³]§Ú­Ì¨Ï¥Î Gauss-Jordan ¤èªk¡A¨Ã¤£§â­ì¨Óªº½u©Ê¥N¼Æ¤èµ{¦¡ªº A ¯x°}¥N²¨ì¦¨¬°³æ¦ì¯x°}¡A¦Ó¬O¥u¤Æ¨ì¦¨¬°¤T¨¤¯x°}¡A¹³¤U­±ªº¨Ò¤l¨º¼Ë¡G

back-subs

ª`·N·sªº A' ¯x°}¬O¤@­Ó¤W¤T¨¤¯x°}¡A¨ä¤¸¯À¤w¸g¥´¤W¤F prime ¼Ð¸¹¥H¥Nªí»P­ì¦³ªº aij ¤£¦P¡A¥t¥~³ÄÀH­nÅܪº±`¼Æ¦V¶q b' ¤]§@ prime ¼Ð°O¡A¦Ó­n¨D¸Ñªº xi «h¤´¬O­ì¨Óªº xi ¨S¦³ÅÜ¡C³o¬O¨Ï¥Î°ª´µ®ø¥hªk§Ú­Ì·|¹w´Áªº¯S©Ê¡C

§â¤@­Ó½u©Ê¥N¼Æ¤èµ{¦¡¾ã²z¨ì¹³¤W¦¡ªº¼Ò¼Ë¡A§Ú­ÌÁöµM¥¢¥h¤Fª½±µÀò±o¤Ï¯x°}ªº¾÷·|[µù]¡A¦ý«o¯à«Ü§Ö¦a±o¥X¹ïÀ³©ó¦V¶q b' ªº¸Ñ¦V¶q x¡Cª½±µÆ[¹î³Ì¤U­±ªº¤@¦C¤èµ{¦¡¡A§Ú­Ì°¨¤W¥i¥H±q¤W¦¡±o¨ì x4 ªºµª®×¡AµM«á¦bª¾¹D x4 ªº±¡ªp¤U¡A ©¹¤W¬Ý§Ú­Ì¤S¥ß§Y½T©w¤F x3 ªº­È¡A¦A©¹¤W´N¤S°ß¤@¨M©w¤F x2¡A¦p¦¹¨ì¤F³Ì¤W­±¤@¦C x1 ¤]©w¥X¨Ó¡A¦b³o­Ó³v¤@¨D¸Ñªº¹Lµ{¤¤¡A«e¤@¨B¨D¥X¤§¥¼ª¾¼Æ¦b¨D¤U¤@­Ó³£­è¦n¦³¥Î¤W¡A³o¥s¤Ï¦V¥N¦^ªk (back-substitution)¡]­Y¤µ¤Ñ¬O§e¤U¤T¨¤¯x°}ªº§Î¦¡¡A«h¬O¥¿¦V¥N¤Jªk (forward-substitution) ¡^¡A¤j®a«Ü²M·¡¦a¥i¥H¬Ý¥X³o¬O¤@­Ó²©ú¦Ó§Ö³tªº¤èªk¡C

[µù]¡G§Y«K¤£¯àª½±µ¦Û°ÊÀò±o¤Ï¯x°}¡A¦b column-augmented §Î¦¡¤U¡A§Ú­Ì¤´¥i¥H¥Î ´X­Ó b ¦V¶q¨Ó "²Õ¦X" ¦¨¤@­Ó³æ¦ì¯x°}¡A¦p¦p¦¹¸Ñ±oªº column-augmented ¤§ x ¦V¶q²Õ´N«ê¦n·|¬O A ªº¤Ï¯x°}¤F¡C

Backsubstotution ³o­Ó¤èªkªºÀ³¥Î»ù­È·|¦b¤U¤@­Ó³æ¤¸ LU Decompotion ¤èªk¤¤¡A§ó¥[¬ðÅã¥X¨Ó¡C