x=matrix(c(rnorm(10,1,3), rnorm(10,7,2), rnorm(10,15,4)), byrow=FALSE, nrow=10)
xc=x
for (k in 1:3) {
xc[,k]=xc[,k]-mean(xc[,k])
}
A=var(xc)
Run Code Online (Sandbox Code Playgroud)
出去
> A
[,1] [,2] [,3]
[1,] 10.166746 -2.619763 -6.717475
[2,] -2.619763 3.291888 3.052898
[3,] -6.717475 3.052898 22.313351
Run Code Online (Sandbox Code Playgroud)
我想解决 PAP^T=I,其中 P 是 3x3,P^T 是 P 的转置,I 是 3x3 单位矩阵。solve(A) 解决了 PA=I,但我想要 PAP^T=I。我找不到答案,将矩阵相乘将花费太长时间。有谁知道如何在 R 或 Python 中做到这一点?我也不想使用 P 可以是 A^(-1/2) 的事实。通过代码的解决方案会很好。
library(stringr)
A=matrix(c(letters[1:4], letters[6:8], letters[10:11]), nrow=3)
mult=function(A, B) {
AB=matrix(nrow=3, ncol=3)
for (r in 1:3) {
for (c in 1:3) {
AB[r,c]=str_c("(", A[r,1], ")*(", B[1,c], ")+(", A[r,2], …Run Code Online (Sandbox Code Playgroud)