# rm(list=ls())
options(OutDec = ",")
#==============================================================================
# Exemplo
#==============================================================================
SIGMA <- matrix(c(19,30,2,12,30,57,5,23,2,5,38,47,12,23,47,68),4,4,T)
L <- matrix(c(4,1,7,2,-1,6,1,8),4,2,T)
PSI <- diag(c(2,4,1,3))
print("==== SIGMA ====")
print(SIGMA)
print("==== L ====")
print(L)
print("==== PSI ====")
print(PSI)
print("==== Verificando os valores ====")
print(L%*%t(L)+PSI)
print("==== Todos iguais a zero ====")
print(SIGMA - (L%*%t(L) + PSI))
[1] "==== SIGMA ===="
[,1] [,2] [,3] [,4]
[1,] 19 30 2 12
[2,] 30 57 5 23
[3,] 2 5 38 47
[4,] 12 23 47 68
[1] "==== L ===="
[,1] [,2]
[1,] 4 1
[2,] 7 2
[3,] -1 6
[4,] 1 8
[1] "==== PSI ===="
[,1] [,2] [,3] [,4]
[1,] 2 0 0 0
[2,] 0 4 0 0
[3,] 0 0 1 0
[4,] 0 0 0 3
[1] "==== Verificando os valores ===="
[,1] [,2] [,3] [,4]
[1,] 19 30 2 12
[2,] 30 57 5 23
[3,] 2 5 38 47
[4,] 12 23 47 68
[1] "==== Todos iguais a zero ===="
[,1] [,2] [,3] [,4]
[1,] 0 0 0 0
[2,] 0 0 0 0
[3,] 0 0 0 0
[4,] 0 0 0 0
#==============================================================================
# Comunalidades
#==============================================================================
sum2 <- function(x){return(sum(x^2))}
h <- apply(L,1,"sum2")
print(h)
[1] 17 53 37 65