Com essa função chega-se ao resultado final da matriz escalonada, porém, não apresenta as matrizes intermediárias até chegar ao resultado final.
A = matrix(c(-2,4,6,0,0,0,-1,1,1,2,0,2),nr=3)
reducedRowEchelonForm <- function(A){
n<-nrow(A)
m<-ncol(A)
i<-j<-1
while(i<=n&&j<=m){
while(j<=m){
currentColumn <- A[,j]
currentColumn[1:n < i] <- 0
# find maximum pivot in current column at or below current row
which <- which.max(abs(currentColumn))
pivot <- currentColumn[which]
if(pivot==0){#checkfor0pivot
j<-j+1
next
5
}
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[,j],row) #sweep
A[i,] <- row # restore current row
j<-j+1
break
}
i<-i+1
}
#0rowstobottom
zeros <- which(ap
ply(A[,1:m], 1, function(x) all(x == 0)))
if (length(zeros) > 0){
zeroRows <- A[zeros,]
A <- A[-zeros,]
A <- rbind(A, zeroRows)
rownames(A) <- NULL
}
A
}
reducedRowEchelonForm(A)
Att.
André
De: Fernando A. Souza < nandodesouza@gmail.com >
Enviada: Quinta-feira, 10 de Outubro de 2013 12:32
Para: r-br@listas.c3sl.ufpr.br
Assunto: Re: [R-br] Função-escalonar
O escalonameno da função matinv() mostra as operações realizadas até chegar no resulado final?
Att.
André
scale() nao e' o q vc procura, Fatima.
Ha' algum tempo, qdo o pacote Design ainda era suportado, havia a funcao matinv() que fazia escalonamento por Gauss-Jordan... mas, atualmente, o pacote nao e' suportado... Se vc tiver uma versao antiga do R, vc ainda pode tentar instala'-lo.
b
_______________________________________________
R-br mailing list
R-br@listas.c3sl.ufpr.br
https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça código mínimo reproduzível.