library(matlib)

Enchelon Form Dengan urutan reduksi baris elementer, setiap matriks memiliki keunikan bentuk eselon dan bentuk eselon tereduksi. Dengan bentuk eselon tereduksi Dengan bentuk eselon tereduksi, kita dapat menjawab pertanyaan mendasar dari sebuah sistem persamaan linear, yaitu, apakah tidak ada solusi, solusi unik, atau tak terhingga banyak solusi dari sistem tersebut. Ingat kembali sistem persamaan linear

A <- matrix(c(0,-2,-1,2,3,2,3,-2,3), nrow =3, ncol = 3)
b <- c(6,-1,2)
A
##      [,1] [,2] [,3]
## [1,]    0    2    3
## [2,]   -2    3   -2
## [3,]   -1    2    3
b
## [1]  6 -1  2
Solve(A,b)
## x1      =           4 
##   x2    =  2.53846154 
##     x3  =  0.30769231
 A <- matrix(c(1, 0, 0, -0.375, 1, -1, 4, 1, 0, 0, 1 ,0.75), nrow =3, ncol = 4)
b <- c(6,-1,2)
A
##      [,1]   [,2] [,3] [,4]
## [1,]    1 -0.375    4 0.00
## [2,]    0  1.000    1 1.00
## [3,]    0 -1.000    0 0.75
b
## [1]  6 -1  2
Solve(A,b)
## x1     - 7.28125*x4  =  1.25 
##   x2      - 0.75*x4  =    -2 
##     x3    + 1.75*x4  =     1

Gaussian Elimination Eliminasi Gaussian adalah algoritma untuk menghitung eselon yang dikurangi dari sebuah matriks dengan menggunakan urutan pengurangan baris elementer. Kita telah melihat beberapa contoh di bagian sebelumnya dan satu contoh di contoh ini tentang bagaimana mendapatkan bentuk eselon atau bentuk eselon tereduksi dari matriks yang diperbesar untuk sebuah sistem persamaan linear untuk menyelesaikan sistem tersebut. Di sini kita menggunakan sistem persamaan linear berikut untuk mendemonstrasikan Eliminasi Gaussian.

A <- matrix(c(1,0,1,0,1,0,0,1,0,1,1,0,0,1,0,1),nrow=4,ncol=4)
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    1    0    0
## [2,]    0    0    1    1
## [3,]    1    0    1    0
## [4,]    0    1    0    1
b <- c(475, 489, 542,422)
b
## [1] 475 489 542 422
Solve(A,b)
## x1     - 1*x4  =   53 
##   x2     + x4  =  422 
##     x3   + x4  =  489 
##             0  =    0

Dalam R kita juga dapat melihat bagaimana cara kerja Eliminasi Gaussian menggunakan menggunakan paket matlib [17]. Kita akan menggunakan contoh di atas. Misalkan kita memiliki sistem persamaan linear berikut ini:

A <- matrix(c(0, -1, 1, 0, 1, 1, 0, 1, 3, -4, 2, 0, -1, 0, 4, -4), 4, 4)
b <- c(1, 1, 5, -2)
showEqn(A, b)
##  0*x1 + 1*x2 + 3*x3 - 1*x4  =   1 
## -1*x1 + 1*x2 - 4*x3 + 0*x4  =   1 
##  1*x1 + 0*x2 + 2*x3 + 4*x4  =   5 
##  0*x1 + 1*x2 + 0*x3 - 4*x4  =  -2

Sekarang dengan menggunakan fungsi echelon() kita dapat melihat bagaimana cara kerja Eliminasi Gaussian bekerja. Dengan contoh ini, kita dapat mengetikkan R sebagai:

echelon(A, b, verbose=TRUE, fractions=TRUE)
## 
## Initial matrix:
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  0    1    3   -1    1  
## [2,] -1    1   -4    0    1  
## [3,]  1    0    2    4    5  
## [4,]  0    1    0   -4   -2  
## 
## row: 1 
## 
##  exchange rows 1 and 2 
##      [,1] [,2] [,3] [,4] [,5]
## [1,] -1    1   -4    0    1  
## [2,]  0    1    3   -1    1  
## [3,]  1    0    2    4    5  
## [4,]  0    1    0   -4   -2  
## 
##  multiply row 1 by -1 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1   -1    4    0   -1  
## [2,]  0    1    3   -1    1  
## [3,]  1    0    2    4    5  
## [4,]  0    1    0   -4   -2  
## 
##  subtract row 1 from row 3 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1   -1    4    0   -1  
## [2,]  0    1    3   -1    1  
## [3,]  0    1   -2    4    6  
## [4,]  0    1    0   -4   -2  
## 
## row: 2 
## 
##  multiply row 2 by 1 and add to row 1 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    7   -1    0  
## [2,]  0    1    3   -1    1  
## [3,]  0    1   -2    4    6  
## [4,]  0    1    0   -4   -2  
## 
##  subtract row 2 from row 3 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    7   -1    0  
## [2,]  0    1    3   -1    1  
## [3,]  0    0   -5    5    5  
## [4,]  0    1    0   -4   -2  
## 
##  subtract row 2 from row 4 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    7   -1    0  
## [2,]  0    1    3   -1    1  
## [3,]  0    0   -5    5    5  
## [4,]  0    0   -3   -3   -3  
## 
## row: 3 
## 
##  multiply row 3 by -1/5 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    7   -1    0  
## [2,]  0    1    3   -1    1  
## [3,]  0    0    1   -1   -1  
## [4,]  0    0   -3   -3   -3  
## 
##  multiply row 3 by 7 and subtract from row 1 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    0    6    7  
## [2,]  0    1    3   -1    1  
## [3,]  0    0    1   -1   -1  
## [4,]  0    0   -3   -3   -3  
## 
##  multiply row 3 by 3 and subtract from row 2 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    0    6    7  
## [2,]  0    1    0    2    4  
## [3,]  0    0    1   -1   -1  
## [4,]  0    0   -3   -3   -3  
## 
##  multiply row 3 by 3 and add to row 4 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    0    6    7  
## [2,]  0    1    0    2    4  
## [3,]  0    0    1   -1   -1  
## [4,]  0    0    0   -6   -6  
## 
## row: 4 
## 
##  multiply row 4 by -1/6 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    0    6    7  
## [2,]  0    1    0    2    4  
## [3,]  0    0    1   -1   -1  
## [4,]  0    0    0    1    1  
## 
##  multiply row 4 by 6 and subtract from row 1 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    0    0    1  
## [2,]  0    1    0    2    4  
## [3,]  0    0    1   -1   -1  
## [4,]  0    0    0    1    1  
## 
##  multiply row 4 by 2 and subtract from row 2 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  1    0    0    0    1  
## [2,]  0    1    0    0    2  
## [3,]  0    0    1   -1   -1  
## [4,]  0    0    0    1    1  
## 
##  multiply row 4 by 1 and add to row 3 
##      [,1] [,2] [,3] [,4] [,5]
## [1,] 1    0    0    0    1   
## [2,] 0    1    0    0    2   
## [3,] 0    0    1    0    0   
## [4,] 0    0    0    1    1
A <- matrix(c(0, -9, 4, 4, 5, 6, 3, 8, 4, 6, 0, 4, 7, 7, 5, 12), 4, 4)
b <- c(-9, -17, -3, 0)
showEqn(A, b)
##  0*x1 + 5*x2 + 4*x3  + 7*x4  =   -9 
## -9*x1 + 6*x2 + 6*x3  + 7*x4  =  -17 
##  4*x1 + 3*x2 + 0*x3  + 5*x4  =   -3 
##  4*x1 + 8*x2 + 4*x3 + 12*x4  =    0
echelon(A, b, verbose=TRUE, fractions=TRUE)
## 
## Initial matrix:
##      [,1] [,2] [,3] [,4] [,5]
## [1,]   0    5    4    7   -9 
## [2,]  -9    6    6    7  -17 
## [3,]   4    3    0    5   -3 
## [4,]   4    8    4   12    0 
## 
## row: 1 
## 
##  exchange rows 1 and 2 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  -9    6    6    7  -17 
## [2,]   0    5    4    7   -9 
## [3,]   4    3    0    5   -3 
## [4,]   4    8    4   12    0 
## 
##  multiply row 1 by -1/9 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1 -2/3 -2/3 -7/9 17/9
## [2,]    0    5    4    7   -9
## [3,]    4    3    0    5   -3
## [4,]    4    8    4   12    0
## 
##  multiply row 1 by 4 and subtract from row 3 
##      [,1]  [,2]  [,3]  [,4]  [,5] 
## [1,]     1  -2/3  -2/3  -7/9  17/9
## [2,]     0     5     4     7    -9
## [3,]     0  17/3   8/3  73/9 -95/9
## [4,]     4     8     4    12     0
## 
##  multiply row 1 by 4 and subtract from row 4 
##      [,1]  [,2]  [,3]  [,4]  [,5] 
## [1,]     1  -2/3  -2/3  -7/9  17/9
## [2,]     0     5     4     7    -9
## [3,]     0  17/3   8/3  73/9 -95/9
## [4,]     0  32/3  20/3 136/9 -68/9
## 
## row: 2 
## 
##  exchange rows 2 and 4 
##      [,1]  [,2]  [,3]  [,4]  [,5] 
## [1,]     1  -2/3  -2/3  -7/9  17/9
## [2,]     0  32/3  20/3 136/9 -68/9
## [3,]     0  17/3   8/3  73/9 -95/9
## [4,]     0     5     4     7    -9
## 
##  multiply row 2 by 3/32 
##      [,1]   [,2]   [,3]   [,4]   [,5]  
## [1,]      1   -2/3   -2/3   -7/9   17/9
## [2,]      0      1    5/8  17/12 -17/24
## [3,]      0   17/3    8/3   73/9  -95/9
## [4,]      0      5      4      7     -9
## 
##  multiply row 2 by 2/3 and add to row 1 
##      [,1]   [,2]   [,3]   [,4]   [,5]  
## [1,]      1      0   -1/4    1/6  17/12
## [2,]      0      1    5/8  17/12 -17/24
## [3,]      0   17/3    8/3   73/9  -95/9
## [4,]      0      5      4      7     -9
## 
##  multiply row 2 by 17/3 and subtract from row 3 
##      [,1]    [,2]    [,3]    [,4]    [,5]   
## [1,]       1       0    -1/4     1/6   17/12
## [2,]       0       1     5/8   17/12  -17/24
## [3,]       0       0    -7/8    1/12 -157/24
## [4,]       0       5       4       7      -9
## 
##  multiply row 2 by 5 and subtract from row 4 
##      [,1]    [,2]    [,3]    [,4]    [,5]   
## [1,]       1       0    -1/4     1/6   17/12
## [2,]       0       1     5/8   17/12  -17/24
## [3,]       0       0    -7/8    1/12 -157/24
## [4,]       0       0     7/8   -1/12 -131/24
## 
## row: 3 
## 
##  exchange rows 3 and 4 
##      [,1]    [,2]    [,3]    [,4]    [,5]   
## [1,]       1       0    -1/4     1/6   17/12
## [2,]       0       1     5/8   17/12  -17/24
## [3,]       0       0     7/8   -1/12 -131/24
## [4,]       0       0    -7/8    1/12 -157/24
## 
##  multiply row 3 by 8/7 
##      [,1]    [,2]    [,3]    [,4]    [,5]   
## [1,]       1       0    -1/4     1/6   17/12
## [2,]       0       1     5/8   17/12  -17/24
## [3,]       0       0       1   -2/21 -131/21
## [4,]       0       0    -7/8    1/12 -157/24
## 
##  multiply row 3 by 1/4 and add to row 1 
##      [,1]    [,2]    [,3]    [,4]    [,5]   
## [1,]       1       0       0     1/7    -1/7
## [2,]       0       1     5/8   17/12  -17/24
## [3,]       0       0       1   -2/21 -131/21
## [4,]       0       0    -7/8    1/12 -157/24
## 
##  multiply row 3 by 5/8 and subtract from row 2 
##      [,1]    [,2]    [,3]    [,4]    [,5]   
## [1,]       1       0       0     1/7    -1/7
## [2,]       0       1       0   31/21   67/21
## [3,]       0       0       1   -2/21 -131/21
## [4,]       0       0    -7/8    1/12 -157/24
## 
##  multiply row 3 by 7/8 and add to row 4 
##      [,1]    [,2]    [,3]    [,4]    [,5]   
## [1,]       1       0       0     1/7    -1/7
## [2,]       0       1       0   31/21   67/21
## [3,]       0       0       1   -2/21 -131/21
## [4,]       0       0       0       0     -12
## 
## row: 4