Subject: Is there a package for physics vector notation?
From: Jaime Villate
Date: Sat, 10 Mar 2012 20:08:41 +0000
On 03/10/2012 06:25 PM, Richard Hennessy wrote:
> Thanks, this is just what I have been looking for. The only thing is,
> I don't mind the answers coming back as lists except when you have to
> use the answer as input in another computation, then you would have to
> turn the list back into i,j,k notation. Is that something you have
> done? I may be able to figure out something, or not.
You can do further calculations with the results, because the . and ?
operators accept lists are their arguments:
(%i4) v1: .7*i - 3.4*j - .6*k;
(%o4) [0.7,-3.4,-0.6]
(%i5) v2: 1.4*i + 6.9*j - 9.78*k;
(%o5) [1.4,6.9,-9.78]
(%i6) v1?v2;
(%o6) [37.392,6.006,9.59]
(%i7) 3*% ? [2,0,-3];
(%o7) [-54.054,394.068,-36.036]
Only when I have to put the result back into a text file, for instance
for the answers in a multiple-choice quiz
generated from Maxima, do I have to go back to the i, j, k notation. In
those cases I use the following:
(%i8) print_vector (%);
(%o8) "-54.054*i-394.068*j-36.036*k"
Notice that the result is a string and cannot be used to make
calculations. The function print_vector above has been defined as:
print_vector(x) := block ([res],
if (first(x) # 0) then res: printf (false, "~a*i", first(x)),
if (length (x) > 1) then
(if (second(x) # 0) then
(if (second(x) < 0)
then res: concat (res, printf( false, "~a*j", second(x)))
else res: concat (res, printf( false, "-~a*j", second(x))))),
if (length (x) > 2) then
(if (third (x) # 0) then
(if (third(x) < 0)
then res: concat (res, printf( false, "~a*k", third(x)))
else res: concat (res, printf( false, "-~a*k", third(x))))),
printf(false, "~a", res))$
There might be more clever ways to achieve that. print_vector only works
for vectors with numerical components and not for vectors with
expressions in their components.
Cheers,
Jaime