# Problem with Syntax of arrays

I am not completely used to the syntax required yet, so this might be a trivial question. I want to introduce a function I need for my model, in which I sum over the product between <a|C|a> (a is a vector and C an array of matrices) and an array of vectors (legendre). My intention was to select one of the matrices from the array of matrices and one of the vectors from the array of vectors and then sum over those products.

functions {
vector sum_abc(real N, real N_i, vector a, vector b, matrix[N] C_r,
matrix[N] C_i, vector[N] legendre){
vector[N_i] sum_over;
real intermediate;
sum_over = 0;
for n in(1:N){
intermediate = a' * C_r[n] * a + b' * C_r[n] * b;
intermediate += b' * C_i[n] * a - a' * C_i[n] * b;
sum_over += intermediate * legendre[n];

}
return sum_over;
}
}

The error I am getting is the following.

RuntimeError: Exception while compiling program_code: ValueError('Syntax error in \'/tmp/httpstan_fnnyv8zo/model_hunv7ya4.stan\', line 3, column 64 to column 65, parsing error:\n -------------------------------------------------\n 1: \n 2: functions {\n 3: vector sum_abc(real N, real N_i, vector a, vector b, matrix[N] C_r, \n ^\n 4: matrix[N] C_i, vector[N] legendre){\n 5: vector[N_i] sum_over;\n -------------------------------------------------\n\n"[" (list of commas) "]" expected in unsized return type of function definition.')

I am unsure what I am doing wrong.

What stands out initially are the definitions of the input matrices:

matrix[N] C_r
matrix[N] C_i

Matrices in stan need to be defined with the row and column:

matrix[R1,C1] C_r
matrix[R2,C2] C_i

If you want to declare an array of matrices, of length N, then you specify:

matrix[R1,C1] C_r[N]
matrix[R2,C2] C_i[N]