Question: sum(...) doesn't seem to like values from a Matrix, why?

Ok I have already defined f as a procedure earlier on, so here is where i am having a problem:

 

M:=Matrix(3,(i,j)->f(i,j));
                          
g:=proc(M,i,j);
op(2,M[i,j])*op(1,M[i,j])*(2-op(1,M[i,j]))
end proc:
 

eq:=op(2,M[1,2])=g(M,2,2)+g(M,3,2);
                            eq:=  4 = x[12] + x[24]

eq1:=op(2,M[1,2])=sum( g(M,i,2) , i=2..3 );
Error, (in g) bad index into Matrix

What is going wrong here? The Matrix has elements which are lists with three elements each, and the procedure g outputs the second element, effectively. As you can see with the expression 'eq', it's happy to accept as an equation when you add g(M,2,2) and g(M,3,2) seperately, but why does it give an error when you write this as sum( g(M,i,2) , i=2..3) ? surely this hsould be exactly the same thing. I have also tried this with add, but the error still occurs. Can anyone help? (By the way, the reason that it's important  to have it as a sum is because I'm planning to generalise it to an 8x8 matrix later on, where every cell will have a corresponding sum.

Please help! thanks very much.

Please Wait...