Is there a package for physics vector notation?



I figured out a solution that I thought I should share.  I changed the 
definition of dotp() to

/* dot product */
dotp(x,y) := realpart(expand(x . conjugate(y)));

Now everything works fine.

Thanks Leo,

Rich

-----Original Message----- 
From: Richard Hennessy
Sent: Saturday, March 10, 2012 3:43 PM
To: Leo Butler
Cc: maxima at math.utexas.edu
Subject: Re: [Maxima] Is there a package for physics vector notation?

"Knowing this, we can write rules for the simplifier to do what you want:"

I can't get this to work for some reason.  I tried copying your code into
Maxima, but for the dot product, I get wrong results.

v1:6*%I+4*%K;
v2:4.4*%I-3.7*%J+8.9*%K;

(%i23) xp(v1,v2);  // OK
(%o23) -22.2*%K-35.8*%J+14.8*%I
(%i24) dotp(v1,v2);

(%o24) 'realpart((4*%K+6*%I) . (-8.9*%K+3.7*%J-4.4*%I))
(%i25) ev(%);

(%o25) 'realpart((4*%K+6*%I) . (-8.9*%K+3.7*%J-4.4*%I))
(%i26) ev(%,nouns);

(%o26) 'realpart((4*%K+6*%I) . (-8.9*%K+3.7*%J-4.4*%I))
(%i27) 6*4.4+4*8.9;

(%o27) 62.0
(%i28) expand(dotp(v1,v2));

(%o28) 'realpart(22.2*%K+35.8*%J-14.8*%I+62.0)

This does not simplify to 62.0.  BTW it is a fascinating and curious thing
that this way works at all.  I suppose if I understood the article you
mentioned better I would know why. I did take a look, but I found it
contained too much terminology that I don't know.

Rich


-----Original Message----- 
From: Leo Butler
Sent: Saturday, March 10, 2012 1:41 PM
To: Richard Hennessy
Cc: maxima at math.utexas.edu
Subject: Re: [Maxima] Is there a package for physics vector notation?

Richard Hennessy <rich.hennessy at verizon.net> writes:

> Hi,
>
> I want to use Maxima to use i, j, k notation for vectors and have a dot
> product and cross product operation for two vectors inputted this way.  I
> have quickly tried the dirty method below but if there is something 
> already
> written then maybe I can avoid reinventing the wheel.

Rich, you may not know this, but this notation is actually a legacy of
the quaternions. Baez spins a nice yarn here
http://math.ucr.edu/home/baez/octonions/octonions.html

In particular, R^3 is the subspace of purely imaginary quaternions, the
cross product is the imaginary part of x . y, and the dot product is the
real part of x . conjuage(y).

Knowing this, we can write rules for the simplifier to do what you want:

kill(all);
qbasis:{%I,%J,%K};
declare([%I,%J,%K],imaginary);
dotscrules:true $
tellsimp(%I . %I, -1);
tellsimp(%J . %J, -1);
tellsimp(%K . %K, -1);
tellsimp(%I . %J, %K);
tellsimp(%J . %I, -%K);
tellsimp(%J . %K, %I);
tellsimp(%K . %J, -%I);
tellsimp(%K . %I, %J);
tellsimp(%I . %K, -%J);


/* cross product */
xp(a,b) := block([x:expand(a . b)], x-realpart(x))$
x : 3*%I $
y : 4*%J $
xp(x,y);
declare([r,s],scalar);
xp(r*%I + 4*%K, r*%J);

/* dot product */
dotp(x,y) := realpart(x . conjugate(y));
dotp(x,y);

You may prefer infix notation for these operators, but the ascii
character set is so small that I prefer not to do this.

Leo

>
> (%i9) reset();
> (%o1)
> (%i2) kill(rules);
> (%o2)
> (%i3) kill(all);
> (%o0)
> (%i1) display2d:false;
>
> (%o1) false
> (%i2) tellsimp(i*i,1);
>
> (%o2) [?\^rule7,?simpexpt]
> (%i3) tellsimp(j*j,1);
>
> (%o3) [?\^rule8,?\^rule7,?simpexpt]
> (%i4) tellsimp(k*k,1);
>
> (%o4) [?\^rule9,?\^rule8,?\^rule7,?simpexpt]
> (%i5) v1=.7*i-3.4*j-.6*k;
>
> (%o5) v1 = -0.6*k-3.4*j+0.7*i
> (%i6) v2=1.4*i+6.9*j-9.78*k;
>
> (%o6) v2 = -9.779999999999999*k+6.9*j+1.4*i
> (%i7) v1*v2,%o5,%o6;
>
> (%o7) (-9.779999999999999*k+6.9*j+1.4*i)*(-0.6*k-3.4*j+0.7*i)
> (%i8) expand(%);
>
> (%o8) 29.112*j*k-7.685999999999999*i*k+0.07*i*j-16.612
>
> I can pick off the answer as the last item in the last sum (-16.612).  Is
> there another way?  As far as the cross product is concerned, I know there
> already is a way using matrices, but I want to avoid that too.
>
> Rich
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>

-- 
Leo Butler                <l_butler at users.sourceforge.net>
SDF Public Access UNIX System -   http://sdf.lonestar.org

_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima