# Maxima vector magnitude and cross product

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

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]


If you don't mind using lists as vectors a very simple solution would be functions::

cross(u, v) := [u[2] * v[3] - v[2] * u[3], v[1] * u[3] - u[1] * v[3], u[1] * v[2] - v[1] * u[2]]$$dot(u, v) := u[1] * v[1] + u[2] * v[2] + u[3] * v[3]$$
norm(u) := sqrt(dot(u, u))$ this is not an ideal nor safe solution but a concise one. 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. Here is the code that defines the cross product of (n-1) vectors of R^n: (%i1) cross([vv]):=block([n,U], n:length(vv)+1, U:args(ident(n)), (-1)^(n+1)determinant(apply(matrix,cons(U,vv))) )$

(%i2) cross([a,b]);
(%o2) [-b,a]

(%i3) cross([a,b,c],[x,y,z]);
(%o3) [bz-cy,cx-az,ay-bx]

(%i4) cross([a,b,c,d],[x,y,z,w],[α,β,γ,δ]);
(%o4) [-b(zδ-wγ)+c*(yδ-wβ)-d*(yγ-zβ),a*(zδ-wγ)-c*(xδ-wα)+d*(xγ-zα),-a*(yδ-wβ)+b*(xδ-wα)-d*(xβ-yα),a*(yγ-zβ)-b*(xγ-zα)+c*(xβ-yα)]

• Why do you format your whole post as citation? Commented May 30 at 3:39
• As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
– Community Bot
Commented May 30 at 3:43
• Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
– Community Bot
Commented May 30 at 4:52