Maxima vector magnitude and cross product

16.8k Views Asked by At

I'm new to maxima. And I have two questions:

1. Question I have a little problem with computing vector's magnitude. Now I'm using such form as

sqrt(v1.v1)

This code looks very ugly.

2. Question I thought vector cross product is expressed like a~b. but Maxima says ~ is not an infix operator

2

There are 2 best solutions below

0
On BEST ANSWER

As far as I know, there is no built-in function to calculate a vector's magnitude, but you can easily define your own:

(%i1) norm(x) := sqrt(x . x)$
(%i2) norm([1, 1]);
(%o2)                               sqrt(2)

The cross product operator ~ is only available after loading 'vect':

(%i1) load("vect")$
(%i2) [1, 2, 3] ~ [2, 3, 4];
(%o2)                        [1, 2, 3] ~ [2, 3, 4]
(%i3) express(%);
(%o3)                            [- 1, 2, - 1]
0
On

well, I didn't like the vec library, so I decided to write my own functions. here it goes:

/*this function gets 3 values as elements of a 3D vector and gives a (3,1) column matrix as the representation of the vector */
vec(vec_tempvar_a1,vec_tempvar_b1,vec_tempvar_c1):=block(
matrix([vec_tempvar_a1],[vec_tempvar_b1],[vec_tempvar_c1]))$

/*this function gets a (3,1) column matrix as representation of a 3D vector and delivers a scalar as the magnitude of the vector*/
vecmag(vecmag_tempvar_V1):= block(
sqrt(transpose(vecmag_tempvar_V1).vecmag_tempvar_V1))$


dotprod(dotprod_tempvar_V1,dotprod_tempvar_V2):=block(
transpose(dotprod_tempvar_V1).dotprod_tempvar_V2)$

/*this function calculates the vector/cross product of the vector on the left on the vector on the right*/

crosprod(crosprod_temvar_V1,crosprod_temvar_V2):= block(
matrix([(crosprod_temvar_V1[2,1]*crosprod_temvar_V2[3,1]-crosprod_temvar_V1[3,1]*crosprod_temvar_V2[2,1])],
       [(crosprod_temvar_V1[3,1]*crosprod_temvar_V2[1,1]-crosprod_temvar_V1[1,1]*crosprod_temvar_V2[3,1])],
       [(crosprod_temvar_V1[1,1]*crosprod_temvar_V2[2,1]-crosprod_temvar_V1[2,1]*crosprod_temvar_V2[1,1])])
)$

I have also been working on a maxima library for rigitd body dynamics, specially robotic applications using screw theory in particular. you may find it at github.com/Foadfs/RMaxima.