Sekarang matriks yang diperbesar berada dalam bentuk eselon tereduksi.Jika eselon tereduksi bentuk memiliki bentuk ini, yaitu matriks koefisien dari matriks yang diperbesar dalam bentuk eselon tereduksi untuk sistem persamaan linier adalah matriks identitas,maka ada solusi unik untuk sistem persamaan linier.

library(matlib)

Kemudian kita membuat matriks koefisien dan vektor untuk ruas kanan dari sistem persamaan linear.

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)

Di sini, kami tidak mengetikkan “nrow=” dan “ncol=”. Jika sudah jelas bisa kita lewati mengetik mereka. Dengan menggunakan fungsi showEqn() kita dapat melihat sistem persamaan linear.

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 eselon() kita dapat melihat bagaimana Penghapusan Gaussian bekerja. Dengan contoh ini, kita dapat mengetikkan R sebagai:

Jika opsi “fraksi” ini disetel sebagai “BENAR”, maka hasilnya dalam bentuk angka rasional. R menampilkan yang berikut ini sebagai cara kerja Penghapusan Gaussian:

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

Jadi solusi untuk sistem ini adalah x1 = 1, x2 = 2, x3 = 0, x4 = 1.