Pesquisar neste blog

08/04/2026

Operações com Matrizes em linguagem R

require(matrixcalc)
require(Matrix)
require(ibd)
require(pracma)
require(matlib)
require(MASS)


###Matriz triangular inferior: utilizando o lower.triangle (matrixcalc)

A=matrix(-8:7,byrow=T,nrow=4)
lower.triangle(A)


#####Matriz triangular superior: utilizando o upper.triangle (matrixcalc)

upper.triangle(A)

####Matriz diagonal (ou antidiagonal): utilizando diag

diag(1:5)

diag(1:5)[5:1,]

####Matriz identidade

dim=5
diag(1,dim)

###Matriz transposta:

t(A)


###Operações com matrizes

A=matrix(c(1:8,-9),byrow=T,nrow=3)
B=matrix(c(4,8,9,5,6,2,3,2,2),byrow=T,nrow=3)
A+B
A-B
A %*% B
det(A)
det(B)
t(A)
round(solve(A),2)

###Potências de Matriz

##A^2

A=matrix(1:9,byrow=T,ncol=3)
A %*% A

###A^3

A %*% A %*% A

####Simplificando as tarefas com o comando matrix.power(matrixcalc)

matrix.power(A,2)

###Formas escalonadas

A=matrix(c(4,2,2,2,2,0,2,0,2),byrow=T,nrow=3)
gaussianElimination(A,verbose=T) 


###Outra alternativa é utilizar o comando rref(pracma) que traz a forma reduzida sem mostrar detalhes:

rref(A)


####Posto de uma matriz

Rank(A)

### Classificação com relação ao posto

A=matrix(1:9,ncol=3,byrow=T)
rref(A)
Rank(A)
###A tem posto incompleto

B=matrix(1:10,ncol=5,byrow=T)
rref(B)
Rank(B)
###B tem posto linha completo


C=matrix(-5:4,ncol=2,byrow=T)
rref(C)
Rank(C)
###C tem posto coluna completo

D=matrix(c(-5,1,3,2,5,9,12,-7,9,13,11,-10,-2,5,7,1),byrow=T,ncol=4)
rref(D)
Rank(D)
##D tem posto completo



Nenhum comentário: