Re: floating point issue
- To: mathgroup at smc.vnet.net
- Subject: [mg86780] Re: floating point issue
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Thu, 20 Mar 2008 05:49:49 -0500 (EST)
- Organization: University of Bergen
- References: <frt59r$sma$1@smc.vnet.net>
Chris Scullard wrote: > Hi everyone, > > I wonder if I can get some opinions on the best way to deal with this > precision issue I am having. I define the vectors: > > K = {111.5, 10.5, 1.5} > g={-0.7071068, 0., -0.7071068} > > And I need this: > > K.Cross[K, g] > > to be 0 in accordance with a vector identity. The answer comes out to > around 1.3 x 10^(-13), which is certainly close to 0 but not close > enough for what I'm doing. I've tried various things like writing out > the cross product explicitly without using the functions but the result > is the same. And using N in various places doesn't seem to help either. > What's the standard solution for this kind of thing? I can't reproduce the problem with versions 5.2 or 6. But you could consider using exact numbers or symbols instead of machine precision numbers. Also, avoid using identifiers starting with capital letters to prevent collisions with built-in names. "K" is a built-in symbol.