MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Strange behavior of Cross[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41909] Strange behavior of Cross[]
  • From: "Christopher J. Henrich" <chenrich at monmouth.com>
  • Date: Mon, 9 Jun 2003 05:20:54 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I have just been surprised by the behavior of the built-in function
Cross[].  I am using it in the common case of two three-dimensional
vectors.  Their components are michine-precision numbers, but one is
exactly the minus of the other.  Here they are:
v = List[0.`, 0.8506508083520401`, -0.5257311121191337`];
w = List[0.`, -0.8506508083520401`, 0.5257311121191337`];

and here is their cross product:
{-4.465198088656736`*^-17, 0.`, 0.`}

I implemented my own naive Cross:
MyCross[{a_, b_, c_}, {p_, q_, r_}] := 
{-c q + b r, c p - a r, -b p + a q};

and tried it out on v and w:
MyCross[v, w]
with this result:
{0., 0., 0.}

What could be happening here?  

 Cross[] has a more general definition.  When there are n-1 arguments,
each of them a vector with n components, the value is another vector
with n components.  In principle, each component of the value is the
determinant of a matrix formed from the components of the arguments.  I
conjecture that Mathematica uses some general determinant evaluator,
which for machine precision numbers is not the same as the simple
expressions I used to define MyCross.

So maybe this isn't a bug. It's just another encounter with the
wonderful world of floating point arithmetic.

-- 
Chris Henrich
(random signature)


  • Prev by Date: Re: "Sloppy Union"? (Union of a list with *nearly* equal elements)
  • Next by Date: Re: "Sloppy Union"? (Union of a list with *nearly* equal elements)
  • Previous by thread: Re: how to generate pulse function ?
  • Next by thread: Re: Strange behavior of Cross[]