Re: Need Math Instruction [message #83436] |
Wed, 06 March 2013 20:52  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
Is it -4*arec or -4*arec*crec?
-Jeremy.
On 3/6/13 7:22 PM, David Fanning wrote:
> Folks,
>
> I need some help with a math problem. Here are some values and an
> expression. The result of the expression is a NaN.
>
> arec= 7.0380332e-005
> brec= 0.011374851
> crec= 0.010008938
> drec= 3.8378659e-005
> Tprec = (brec-(brec^2 -4*arec)^(1.0/2))/(2*arec)
>
> IDL> help, Tprec
> TPREC FLOAT = -NaN
>
> I want to know why this is a NaN and how to explain the following
> results:
>
> IDL> help, brec, arec
> BREC FLOAT = 0.0113749
> AREC FLOAT = 7.03803e-005
>
> IDL> print, (brec^2 -4*arec)
> -0.000152134
> IDL> d = (brec^2 -4*arec)
> IDL> help, d
> D FLOAT = -0.000152134
>
> IDL> print, d^(1.0/2)
> -NaN
>
> IDL> print, -0.000152134^(1.0/2)
> -0.0123343
>
> IDL> print, d, format='(F0.12)'
> -0.000152134089
>
> IDL> print, -0.000152134089D^(1.0/2)
> -0.012334265
>
> IDL> print, Float(-0.0001521340891486)^(1.0/2)
> -NaN
>
> IDL> print, -0.0001521340891486^(1.0/2)
> -0.0123343
>
> IDL> print, Double(-0.0001521340891486D)^(1.0/2)
> -NaN
>
> IDL> print, -0.0001521340891486D^(1.0/2)
> -0.012334265
>
> Any ideas?
>
> Thanks,
>
> David
>
|
|
|
|
Re: Need Math Instruction [message #83438 is a reply to message #83437] |
Wed, 06 March 2013 18:30   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
An exponent has higher precedence that negation. So
IDL> print,(-0.5)^(0.5)
-NaN
% Program caused arithmetic error: Floating illegal operand
i.e. you can't take the square root of a negative number, but
IDL> print,-0.5^(0.5)
-0.707107
says to negate the result of 0.5^(0.5)
--Wayne
On Wednesday, March 6, 2013 8:22:00 PM UTC-5, David Fanning wrote:
> Folks,
>
>
>
> I need some help with a math problem. Here are some values and an
>
> expression. The result of the expression is a NaN.
>
>
>
> arec= 7.0380332e-005
>
> brec= 0.011374851
>
> crec= 0.010008938
>
> drec= 3.8378659e-005
>
> Tprec = (brec-(brec^2 -4*arec)^(1.0/2))/(2*arec)
>
>
>
> IDL> help, Tprec
>
> TPREC FLOAT = -NaN
>
>
>
> I want to know why this is a NaN and how to explain the following
>
> results:
>
>
>
> IDL> help, brec, arec
>
> BREC FLOAT = 0.0113749
>
> AREC FLOAT = 7.03803e-005
>
>
>
> IDL> print, (brec^2 -4*arec)
>
> -0.000152134
>
> IDL> d = (brec^2 -4*arec)
>
> IDL> help, d
>
> D FLOAT = -0.000152134
>
>
>
> IDL> print, d^(1.0/2)
>
> -NaN
>
>
>
> IDL> print, -0.000152134^(1.0/2)
>
> -0.0123343
>
>
>
> IDL> print, d, format='(F0.12)'
>
> -0.000152134089
>
>
>
> IDL> print, -0.000152134089D^(1.0/2)
>
> -0.012334265
>
>
>
> IDL> print, Float(-0.0001521340891486)^(1.0/2)
>
> -NaN
>
>
>
> IDL> print, -0.0001521340891486^(1.0/2)
>
> -0.0123343
>
>
>
> IDL> print, Double(-0.0001521340891486D)^(1.0/2)
>
> -NaN
>
>
>
> IDL> print, -0.0001521340891486D^(1.0/2)
>
> -0.012334265
>
>
>
> Any ideas?
>
>
>
> Thanks,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: Need Math Instruction [message #83502 is a reply to message #83436] |
Thu, 07 March 2013 14:30  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Wednesday, March 6, 2013 11:52:54 PM UTC-5, Jeremy Bailin wrote:
> Is it -4*arec or -4*arec*crec?
Hah, nice catch! David, you should check your math again. Also whether the first term should be -BREC.
Craig
|
|
|