I am trying to find the dot product of two matrices in R. In the q matrix, which must be transposed, I have three different q values that I randomly generated earlier, and in the z matrix three randomly generated z values that serve as coordinates of a random point i. I have:
z0= NULL
for (i in 1:100){
z0[i]= 1
}
z1= runif(100, min=0, max= 20)
z2= runif(100, min=0, max=20)
q0= runif(1, 0, 1)
q1= runif(1, 0, 1)
q2= runif(1, 0, 1)
i= runif(1, 1, 101)
i= ceiling(i-1)
q= matrix(c(q0,q1,q2), ncol=3)
z= matrix(c(z0[i],z1[i],z2[i]), ncol=3)
s[i]= t(q)*z
However, when I try to calculate s[i], I get Error in t(q) * z : non-conformable arrays
. I am not sure why this would be as I they seem to both have the same length.
This is my first time using R so I am not really sure what is going on.
Thanks!
q= matrix(c(q0,q1,q2), ncol=3) Error in matrix(c(q0, q1, q2), ncol = 3) : object 'q0' not found
– Sadler%*%
. – Oculomotorset.seed(1)
before therunif
. This is what I getcrossprod(q, z) [,1] [,2] [,3] [1,] 0.7622588 10.68985 14.67339 [2,] 0.8413184 11.79857 16.19527 [3,] 0.8964904 12.57230 17.25733
– Sadlers
? – Endsleyset.seed(1); z1= runif(100, min=0, max= 20);....crossprod(q,z)
– Sadler