length of a vector



maxima-admin@math.utexas.edu wrote on 09/15/2005 08:45:54 AM:

> say a point in 3-d (a,b,c) and another point
> (a1,b1,c1) what is the function to give distance
> between them?

Try something like:

(%i1) distance(p1,p2) := block([listarith : true],
  if listp(p1) and listp(p2) and length(p1) = length(p2) then (
    p1 : map('cabs, p1-p2),
    sqrt(p1.p1))
  else error("The arguments to 'distance' must be equal length lists"))$

(%i3) distance([0,0,0],[1,2,3]);
(%o3) sqrt(14)
(%i4) distance([0,0,0],[1,2*%i,3]);
(%o4) sqrt(14)
(%i5) declare(z,complex);
(%o5) done
(%i6) distance([0,0],[z,0]);
(%o6) sqrt(realpart(z)^2+imagpart(z)^2)
(%i7) distance(a,b);
The arguments to 'distance' must be equal length lists
#0: distance(p1=a,p2=b)
 -- an error.  Quitting.  To debug this try debugmode(true);


Barton