Matrix multiplication

Hi all,
I’m trying to do the following matrix multiplication in the transformed parameters block: K2[C] = A[C,C] * K1[C] for several samples S.

transformed parameters{
vector [S] K1[C];
vector [S] K2[C];
matrix [C,C] A[S];

for (s in 1:S) {
K2[s] = A[s] * K1[s];
}
}

A is supposed to be a one dimensional array of size S containing C × C matrices and K1 and K2 arrays of size S containing vectors of size C.

I’ve tried many ways to do that, but they all result in error. I’m happy to provide more information if needed.

Thanks

That is inconsistent with how you declared them; that should be

transformed parameters {
  vector[C] K1[S];
  vector[C] K2[S];
  ...
}
2 Likes

Thanks so much!