-1

I'm trying to solve matrix in R.I have 3 matrix like this, Uf[11,3], Uft[3,11] and AT[3,3] .For the first two 11 rows and columns represent 11 different values that I want to use. And at last I need to reach 11 different "D"

values.D = (11/3) * Uft * AT * Uf

but if i try this with for loop I had [11,11] matrix .So here is the problem , how can I get [11,1] or [1,11] matrix to see my D results. I also get this error "subscript out of bounds" when I try this code.

for (i in 1:11) {
  print((1/3) * 11 * Uft[[,i]] %*% Uf[[i, ]] %*% AT[[,]])
}

There should be 11 ui vectors to calculates "D" datas.But i have (3,11) matrix instead of 11 ui vectors.

***Here is my Ut matrix(combination of ui).Uft is transpose of Uf.

Now i want to use each row of Uft and each column of Uf and all of AT to calcutes 11 different "D".

  • Welcome to SO! Please explain your problem in more detail, give example input data (with `dput`) and the expected output. Have a look [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) how to make great MREs. – starja Dec 29 '20 at 23:16
  • Thanks for support. Actually i tried to add some details but i cant use this site properly so i culdnt put some datas.I just tried to clarify what i want to do – Selin Ozteber Dec 30 '20 at 02:03

1 Answers1

1

I think you have several syntax errors to be checked:

  • You should use [] rather than [[]] for matrix indexing
  • drop = FALSE should be set

For example

for (i in 1:11) {
  print(11 / 3 * Uft[, i, drop = FALSE] %*% Uf[i, , drop = FALSE] %*% AT)
}
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81