Re: Strange behavior of Cross[]
- To: mathgroup at smc.vnet.net
- Subject: [mg41913] Re: Strange behavior of Cross[]
- From: bobhanlon at aol.com (Bob Hanlon)
- Date: Tue, 10 Jun 2003 04:46:47 -0400 (EDT)
- References: <bc1k29$boc$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
v=List[0.`,0.8506508083520401`,-0.5257311121191337`]; w=List[0.`,-0.8506508083520401`,0.5257311121191337`]; Cross[v, w]//Chop {0, 0, 0} v=Rationalize[List[0.`,0.8506508083520401`,-0.5257311121191337`],0]; w=Rationalize[List[0.`,-0.8506508083520401`,0.5257311121191337`],0]; Cross[v, w] {0, 0, 0} Bob Hanlon In article <bc1k29$boc$1 at smc.vnet.net>, "Christopher J. Henrich" <chenrich at monmouth.com> wrote: << Subject: Strange behavior of Cross[] From: "Christopher J. Henrich" <chenrich at monmouth.com> To: mathgroup at smc.vnet.net Date: Mon, 9 Jun 2003 09:29:45 +0000 (UTC) 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.