Problems about dimensions dismatch

I used this and I think the dimension is matched but get some error report:

    matrix[N,2] u = append_col(resi,resi .* X[,2]);
    vector[2] M = rep_vector(0,2);
    matrix[N,1] D1 =   u * M;

Variable definition base type mismatch, variable declared as base type matrix variable definition has base type vectorVariable definition dimensions mismatch, definition specifies 2, declaration specifies 1

26:      matrix[N,1] D1 =   u * M;

In Stan, multiplying a matrix by a vector returns a vector so you’re trying to assign a vector to a matrix variable. You can either define D1 as a vector (probably the best option) or M as a matrix.