S 4 行列式の展開と逆行列

4.1 問題4.2

A <- matrix(c(1,2,4,5,3,1,7,4,2,3,5,2,1,5,3,6),4,4)
det(A)
## [1] 60
A <- matrix(c(3,-2,-4,1,1,4,3,5,6,-3,-7,3,3,4,5,8),4,4)
det(A)
## [1] 1

4.2 問題4.5

A <- matrix(c(4,3,-1,2),2,2)
matrix(c(2,-3,1,4),2,2)/det(A)
##            [,1]       [,2]
## [1,]  0.1818182 0.09090909
## [2,] -0.2727273 0.36363636
solve(A)
##            [,1]       [,2]
## [1,]  0.1818182 0.09090909
## [2,] -0.2727273 0.36363636
A %*% solve(A)
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
solve(A) %*% A
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
A <- matrix(c(1,2,4,2,3,2,3,5,1),3,3)
det(A)
## [1] 5
solve(A)
##      [,1] [,2] [,3]
## [1,] -1.4  0.8  0.2
## [2,]  3.6 -2.2  0.2
## [3,] -1.6  1.2 -0.2

4.3 例題4.4

連立一次方程式を解く.

A <- matrix(c(1,2,4,2,1,5,3,4,6),3,3)
b <- matrix(c(1,-3,7),3,1)
solve(A,b)
##      [,1]
## [1,]    1
## [2,]    3
## [3,]   -2

4.4 問題4.6

A <- matrix(c(4,3,-1,2),2,2)
b <- matrix(c(24,7),2,1)
solve(A,b)
##      [,1]
## [1,]    5
## [2,]   -4
A <- matrix(c(1,2,4,2,3,2,3,5,1),3,3)
b <- matrix(c(2,5,9),3,1)
solve(A,b)
##      [,1]
## [1,]    3
## [2,]   -2
## [3,]    1

4.5 演習問題4

1

A <- matrix(c(1,2,3,6,1,4,2,5,4),3,3)
det(A)
## [1] 36
A <- matrix(c(2,5,3,4,3,9,1,-2,3),3,3)
det(A)
## [1] 6
A <- matrix(c(9,1,4,6,7,5,2,4,6,2,4,1,5,3,6,-1),4,4)
det(A)
## [1] 216
A <- matrix(c(3,2,2,7,3,7,3,5,4,6,4,3,1,4,2,1),4,4)
det(A)
## [1] 50

2

A <- matrix(c(3,1,5,2),2,2)
if (det(A)!=0) solve(A) else print("正則ではない")
##      [,1] [,2]
## [1,]    2   -5
## [2,]   -1    3
A <- matrix(c(3,1,6,2),2,2)
if (det(A)!=0) solve(A) else print("正則ではない")
## [1] "正則ではない"
A <- matrix(c(-2,-3,-1,4),2,2)
if (det(A)!=0) solve(A) else print("正則ではない")
##            [,1]        [,2]
## [1,] -0.3636364 -0.09090909
## [2,] -0.2727273  0.18181818
A <- matrix(c(3,1,0,2,1,1,-2,0,-1),3,3)
if (det(A)!=0) solve(A) else print("正則ではない")
##            [,1] [,2]       [,3]
## [1,]  0.3333333    0 -0.6666667
## [2,] -0.3333333    1  0.6666667
## [3,] -0.3333333    1 -0.3333333
A <- matrix(c(0,1,-1,3,-2,5,3,-3,6),3,3)
if (det(A)!=0) solve(A) else print("正則ではない")
## [1] "正則ではない"
A <- matrix(c(1,0,1,0,1,1,1,1,0),3,3)
if (det(A)!=0) solve(A) else print("正則ではない")
##      [,1] [,2] [,3]
## [1,]  0.5 -0.5  0.5
## [2,] -0.5  0.5  0.5
## [3,]  0.5  0.5 -0.5