user3453816
user3453816

Reputation: 17

I am trying to make a summation of three matrix

I am trying to make a matrix form such as

Summation from j=0 to 30 [ (A^j%*%V%*%t(A)^j) ]. and A and V is 3 by 3 matrix. therefore, the result should be 3 by 3 matrix form.

for example

A=matrix(1:9, ncol = 3)
V=matrix(1:9, ncol = 3)

and I tried

for (i in 0:30) {
    AVA=sum(A^i%*%V%*%t(A)^i)
}

but it is not working.

Do you have any idea how to do summation of matrix as above?

Upvotes: 0

Views: 119

Answers (2)

C Doan
C Doan

Reputation: 91

AVA=matrix(0,ncol=3,nrow=3)
for(i in 0:30) AVA=AVA + A^i %*% V %*% t(A)^i

This will return a summation matrix for you, not a summation of all elements into an integer

Upvotes: 1

TooTone
TooTone

Reputation: 8126

Try

A=matrix(1:9, ncol = 3)
V=matrix(1:9, ncol = 3)
AVA=matrix(rep(0,9), ncol = 3)
Atopoweri = diag(3) # A to zeroth power
for (i in 0:n) {
    AVA = AVA + Atopoweri%*%V%*%t(Atopoweri)
    Atopoweri = Atopoweri %*% A
}

I'm assuming by ^ you mean matrix power, but if you mean element-wise power then something along the lines of @C Doan's answer is what you want.

Upvotes: 1

Related Questions