axjack's blog

axjack is said to be an abbreviation for An eXistent JApanese Cool Klutz.

行簡約行列をRで

pracmaのrrefを使って行簡約行列を出してみます。これで適当な行列を手計算で簡約化して答え合わせができますね。

ソース

# install.packages('pracma')
# library('pracma')

## 行ベクトルを4本
a1 <- c(1,2,0)
a2 <- c(2,4,0)
a3 <- c(0,1,3)
a4 <- c(1,3,3)

## 行列にする
M <- matrix(c(a1,a2,a3,a4),nrow = 3, ncol=4)

## 行列を表示
print(M)

## 行簡約行列を表示 
rref(M)

## 行列の階数を表示
Rank(M)

実行結果

> a1 <- c(1,2,0)
> a2 <- c(2,4,0)
> a3 <- c(0,1,3)
> a4 <- c(1,3,3)
> M <- matrix(c(a1,a2,a3,a4),nrow = 3, ncol=4)
> print(M)
     [,1] [,2] [,3] [,4]
[1,]    1    2    0    1
[2,]    2    4    1    3
[3,]    0    0    3    3
> Rank(M)
[1] 2
> rref(M)
     [,1] [,2] [,3] [,4]
[1,]    1    2    0    1
[2,]    0    0    1    1
[3,]    0    0    0    0
> 
axjack is said to be an abbreviation for An eXistent JApanese Cool Klutz.