Solving equation containing sum over list of vectors



Hi,

I'm trying to investigate a problem containing the root mean square 
distance of a set of vectors to a set of transformed vectors. The 
transformation is parameterized by some scalar values.

Now I want to minimize the rms distance under variation of the 
transformation parameters by finding the roots of the derivative.
This is where I am stuck right now.

I tried this approach:

v: matrix([vx[i]], [vy[i]], [vz[i]], [1]);
u: matrix([ux[i]], [uy[i]], [uz[i]], [1]);

Rot: matrix(
   [cos(phi),-sin(phi), 0, 0],
   [sin(phi), cos(phi), 0, 0],
   [       0,        0, 1, 0],
   [       0,        0, 0, 1]);

Transl: matrix(
   [1, 0, 0, l*tx],
   [0, 1, 0, l*ty],
   [0, 0, 1, 0],
   [0, 0, 0, 1]);

Center: matrix(
   [1, 0, 0, cx],
   [0, 1, 0, cy],
   [0, 0, 1, 0],
   [0, 0, 0, 1]);

T: invert(Center) . Rot . Center . Transl;

d_rms(phi,l):=
   sum(
     transpose(T . v - u) . (T . v - u) * w[i],
     i,1,n);

d_rms_l: diff(d_rms(phi,l), l);

solve(d_rms_l = 0, l);

The above code does not actually solve for l, which is what I want. And 
which I could perform by hand. (Note: for the last statement we can 
assume everything as constant except for l.)

It may be related to the vector lists v and u and the scalar weight list 
w - I don't know how to declare them as list of vectors and scalars (I 
actually tried declare(v, nonscalar) etc., but it didn't work out).

I would appreciate any help.
Regards,
Matze