Re: A question about Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg34610] Re: A question about Mathematica
- From: Christoph Handel <scone4 at kepler.mechanik.tu-darmstadt.de>
- Date: Wed, 29 May 2002 02:46:47 -0400 (EDT)
- Organization: Technische Universitaet Darmstadt
- References: <acshi7$kei$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Chen-Ying Huang wrote: > I was doing some computations. A computation gives me something like > A/A, another computation gives me something like B/B. I then do a > true-false statement, that is, If [A/A>=B/B, 1, 0]. Since both > computations (A/A and B/B) equal to one, the statement is true and hence > the If statement should lend a 1 as specified. > > However, I found out that the If statement lends a zero because > somehow, in the computations, A/A is less than B/B by the order of 10 to > the power of -16. Since you try to compare numerical results, you must first decide after how many digits you want to stop the comparison. is 1.0000001 equal to 1? or is 1.000000000001 equal to 1? After that you can truncate your expressions to the required number of digits (for example 10) using If[ N[A/A,10] >= N[B/B,10], 1, 0] Greetings Christoph