Newbie question: vector manipulation/simplification



Maxima users,

I have been trying to do a lot of vector manipulations in Maxima lately, but
it seems awkward.  I want to see if there are better methods.

I have 2 vectors a1, a2, (let's say they are 2D vectors), and I want to find
linear combinations of a1 and a2 such that the resulting magnitude is the
value mag.  I am able to find a solution in Maxima, but, it seems a little
messy.  Is there a more elegant way?

Basically, we have a vector of the form (n1*a1 + n2*a2).  Since this is an
incompletely specified problem, I will assume n2 is set n2 and solve for n1
(iterate over n2 later).

(%i2) display2d:false;
(%o2) false

(%i3) a1 : [a1x, a1y];
(%o3) [a1x,a1y]

(%i4) a2 : [a2x, a2y];
(%o4) [a2x,a2y]

(%i8) solve((n1*a1+n2*a2) . (n1*a1+n2*a2) = mag, n1);
(%o8) [n1 = -(sqrt((-a1x^2*a2y^2+2*a1x*a1y*a2x*a2y-a1y^2*a2x^2)*n2^2
                    +(a1y^2+a1x^2)*mag)
          +(a1y*a2y+a1x*a2x)*n2)
          /(a1y^2+a1x^2),
       n1 = (sqrt((-a1x^2*a2y^2+2*a1x*a1y*a2x*a2y-a1y^2*a2x^2)*n2^2
                   +(a1y^2+a1x^2)*mag)
          +(-a1y*a2y-a1x*a2x)*n2)
          /(a1y^2+a1x^2)]

Okay, we have a solution, now can we simplify this to a simpler form?  For
instance, I see some terms that can be expressed as dot products of the
original vectors a1 and a2.

(%i9) subst(maga1^2, (a1y^2+a1x^2), %);
(%o9) [n1 = -(sqrt((-a1x^2*a2y^2+2*a1x*a1y*a2x*a2y-a1y^2*a2x^2)*n2^2
                    +mag*maga1^2)
          +(a1y*a2y+a1x*a2x)*n2)
          /maga1^2,
       n1 = (sqrt((-a1x^2*a2y^2+2*a1x*a1y*a2x*a2y-a1y^2*a2x^2)*n2^2
                   +mag*maga1^2)
          +(-a1y*a2y-a1x*a2x)*n2)
          /maga1^2]

(%i10) subst(a1_dot_a2, (a1y*a2y+a1x*a2x), %);
(%o10) [n1 = -(sqrt((-a1x^2*a2y^2+2*a1x*a1y*a2x*a2y-a1y^2*a2x^2)*n2^2
                     +mag*maga1^2)
           +a1_dot_a2*n2)
           /maga1^2,
        n1 = (sqrt((-a1x^2*a2y^2+2*a1x*a1y*a2x*a2y-a1y^2*a2x^2)*n2^2
                    +mag*maga1^2)
           +(-a1y*a2y-a1x*a2x)*n2)
           /maga1^2]

The other ugly term is related to the magnitude of the cross product of the
two vectors (I think).  Maybe the vect package could help...

(using v1 and v2 here instead of a1 and a2)

(%i13) load(vect);
(%o13) "/Users/smithzv/usr/share/maxima/5.13.99rc2/share/vector/vect.mac"

(%i27) declare([v1, v2], nonscalar);
(%o27) done

(%i31) n1*v1 + n2*v2;
(%o31) n2*v2+n1*v1

(%i34) expand((n1*v1 + n2*v2) . (n1*v1 + n2*v2));
(%o34) (n2*v2) . (n2*v2)+2*(n1*v1) . (n2*v2)+(n1*v1) . (n1*v1)

(%i35) solve(%=mag^2, n1);
(%o35) [(n1*v1) . (n2*v2) = -((n2*v2) . (n2*v2)+(n1*v1) . (n1*v1)-mag^2)/2]

(%i36) vectorsimp(%o34);
(%o36) (n2*v2) . (n2*v2)+2*(n1*v1) . (n2*v2)+(n1*v1) . (n1*v1)

(%i37) vectorsimp(%o35);
(%o37) [(n1*v1) . (n2*v2) = -((n2*v2) . (n2*v2)+(n1*v1) . (n1*v1)-mag^2)/2]

I cannot seem to solve this equation without setting a1 and a2 explicitly to
vectors, but when I do this, it doesn't leave the result in the most useful
form, i.e. something that I or my boss can read at a glance and implement
elsewhere.

How can I do this better?

Thanks,
Zach