Search code examples
vectormaximadot-product

wxmaxima 0.8.4: defining a vector without defining its component


Let's have the following code

e1 : matrix([a1],[b1],[c1]);
e2 : matrix([a2],[b2],[c2]);
dotproduct(e1,e2);

the 3rd line gives the output

a1a2 + b1b2 +c1c2

I would like to have something like this instead (|e| is the norm of e):

|e1||e2|

Is there a way for wxMaxima to give a simplified answer for the dotproduct function ?


Solution

  • Here's a solution, although this isn't entirely satisfactory.

    Instead of calling dotproduct, just write dot products as a . b. (The . operator means noncommutative multiplication in Maxima.) You can define a simplification rule so that a . b simplifies to an expression involving a and b and the angle between them.

    matchdeclare ([aa, bb], nonscalarp);
    tellsimpafter (aa . bb, norm(aa)*norm(bb)*cos(angle(aa, bb)));
    

    With this, I get:

    (%i12) declare ([e1, e2], nonscalar);
    (%o12) done
    (%i13) e1.e2;
    (%o13) norm(e1)*cos(angle(e1,e2))*norm(e2)
    

    Maybe this much is helpful, you can say whether it is. It isn't so great because you'll have to define norm yourself and also angle(a, b). This is a weakness in Maxima -- its coverage of this stuff is hit or miss.

    Or maybe you don't need norm and angle to be defined -- I suppose it depends on your purposes. Maybe you can say more about what is the larger problem you're trying to solve.

    Also, this solution is a little problematic because only a two-term product a . b will match. With three terms, a . b . c, the pattern matcher thinks it doesn't fit. There are various ways around that, again, none of them entirely satisfactory.

    All the same, I hope this is useful to you in some way.