reduced row echelon form
行列のを生成する R の関数はありますか? この参照は、そうではないと言っています。同意しますか?
19334 次
4 に答える
9
pracma パッケージには実装も含まれています。pracma::rref を参照してください。
于 2013-05-02T21:07:33.040 に答える
8
また、線形代数を教えるために開発された最近のパッケージ ( matlib ) もあります。これは、行列のエシェロン形式を計算し、途中で使用されるステップを示します。
library('matlib')
A <- matrix(c(2, 1, -1,-3, -1, 2,-2, 1, 2), 3, 3, byrow=TRUE)
b <- c(8, -11, -3)
echelon(A, b, verbose=TRUE, fractions=TRUE)
Initial matrix:
[,1] [,2] [,3] [,4]
[1,] 2 1 -1 8
[2,] -3 -1 2 -11
[3,] -2 1 2 -3
row: 1
exchange rows 1 and 2
[,1] [,2] [,3] [,4]
[1,] -3 -1 2 -11
[2,] 2 1 -1 8
[3,] -2 1 2 -3
multiply row 1 by -1/3
[,1] [,2] [,3] [,4]
[1,] 1 1/3 -2/3 11/3
[2,] 2 1 -1 8
[3,] -2 1 2 -3
multiply row 1 by 2 and subtract from row 2
[,1] [,2] [,3] [,4]
[1,] 1 1/3 -2/3 11/3
[2,] 0 1/3 1/3 2/3
[3,] -2 1 2 -3
multiply row 1 by 2 and add to row 3
[,1] [,2] [,3] [,4]
[1,] 1 1/3 -2/3 11/3
[2,] 0 1/3 1/3 2/3
[3,] 0 5/3 2/3 13/3
row: 2
exchange rows 2 and 3
[,1] [,2] [,3] [,4]
[1,] 1 1/3 -2/3 11/3
[2,] 0 5/3 2/3 13/3
[3,] 0 1/3 1/3 2/3
multiply row 2 by 3/5
[,1] [,2] [,3] [,4]
[1,] 1 1/3 -2/3 11/3
[2,] 0 1 2/5 13/5
[3,] 0 1/3 1/3 2/3
multiply row 2 by 1/3 and subtract from row 1
[,1] [,2] [,3] [,4]
[1,] 1 0 -4/5 14/5
[2,] 0 1 2/5 13/5
[3,] 0 1/3 1/3 2/3
multiply row 2 by 1/3 and subtract from row 3
[,1] [,2] [,3] [,4]
[1,] 1 0 -4/5 14/5
[2,] 0 1 2/5 13/5
[3,] 0 0 1/5 -1/5
row: 3
multiply row 3 by 5
[,1] [,2] [,3] [,4]
[1,] 1 0 -4/5 14/5
[2,] 0 1 2/5 13/5
[3,] 0 0 1 -1
multiply row 3 by 4/5 and add to row 1
[,1] [,2] [,3] [,4]
[1,] 1 0 0 2
[2,] 0 1 2/5 13/5
[3,] 0 0 1 -1
multiply row 3 by 2/5 and subtract from row 2
[,1] [,2] [,3] [,4]
[1,] 1 0 0 2
[2,] 0 1 0 3
[3,] 0 0 1 -1
于 2016-06-22T15:23:37.597 に答える
4
組み込まれているようには見えませんが、このページでこのrref関数を見つけました。
rref <- function(A, tol=sqrt(.Machine$double.eps),verbose=FALSE,
fractions=FALSE){
## A: coefficient matrix
## tol: tolerance for checking for 0 pivot
## verbose: if TRUE, print intermediate steps
## fractions: try to express nonintegers as rational numbers
## Written by John Fox
if (fractions) {
mass <- require(MASS)
if (!mass) stop("fractions=TRUE needs MASS package")
}
if ((!is.matrix(A)) || (!is.numeric(A)))
stop("argument must be a numeric matrix")
n <- nrow(A)
m <- ncol(A)
for (i in 1:min(c(m, n))){
col <- A[,i]
col[1:n < i] <- 0
# find maximum pivot in current column at or below current row
which <- which.max(abs(col))
pivot <- A[which, i]
if (abs(pivot) <= tol) next # check for 0 pivot
if (which > i) A[c(i, which),] <- A[c(which, i),] # exchange rows
A[i,] <- A[i,]/pivot # pivot
row <- A[i,]
A <- A - outer(A[,i], row) # sweep
A[i,] <- row # restore current row
if (verbose)
if (fractions) print(fractions(A))
else print(round(A,round(abs(log(tol,10)))))
}
for (i in 1:n)
if (max(abs(A[i,1:m])) <= tol)
A[c(i,n),] <- A[c(n,i),] # 0 rows to bottom
if (fractions) fractions (A)
else round(A, round(abs(log(tol,10))))
}
于 2010-06-27T08:17:49.557 に答える