LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sine and Cosine calculations

I need to convert Double Precision Floating Point numbers by taking the Sin and Cosine. I have found that the calculations give inconsistant answers. For instance Cos(90) = 6.123(incorrect) and should be 0, Cos(0)=1 (correct). I tried in degrees and radians.I use labview 7 with XP professional OS.
0 Kudos
Message 1 of 6
(6,707 Views)
Please look again. Make sure you don't clip the result in the indicator. Make the indicator a bit wider!

Cos(PI/2) shows up as 6.123E-17 which is ~0.

You might want to change the formatting of the indicator as "floating point" with a set number of significant digits.
Message 2 of 6
(6,707 Views)
Hi,
I think you're wrong when saying that LV says Cos(90)=6.123. I've tried it and found Cos(90)=6.12303e-17. Your control is probably a bit too small to show you the other digits of the number.

Cos(90)!=0 probably because of an aprox value used for Pi.
Hope this helps !
Julien
Message 3 of 6
(6,707 Views)

So I'm not the only one with the trouble.  Is this something worth worring about for symulation calculations?

0 Kudos
Message 4 of 6
(6,099 Views)

@Fbaird wrote:

So I'm not the only one with the trouble.  Is this something worth worring about for symulation calculations?


No, as long as you are aware of it and not do silly things such as do an "equal zero" on it.

0 Kudos
Message 5 of 6
(6,093 Views)

You see the fundamental problem is that all floating point representations are approximations. Consequently, it is rather easy to come up with calculations that give "wrong" answers. As folks have pointed out you need to always be mindful of the numeric precision that is available -- and that can be trusted. And when working with calculated values never test for absolute equality.

 

On a related track, you also need to be mindful of the results from "invalid" calculations that can return so-called pseudo-values like not-a-number and positive or negative infinity. These values can cause all sorts of mischief.

 

And then there's the ever-popular negative zero (-0)...

 

Mike...

 

Pocket Calculator: (n) An electronic device capable of dividing a ballpark estimate by a wild-ass guess and returning a value accurate to 13 decimal places.


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 6 of 6
(6,062 Views)