From: Alexander B. <ale...@gm...> - 2006-05-25 19:01:29
|
This is not really a numpy issue, but general floating point problem. Consider this: >>> x=3Dlinspace(0,10*pi,11) >>> all(array(map(math.sin, x))=3D=3Dsin(x)) True If anything can be improved, that would be the C math library. On 5/25/06, Rob Hooft <ro...@ho...> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Robert Kern wrote: > | Alan G Isaac wrote: > | > |>I am a user, not a numerics type, > |>so this is undoubtedly a naive question. > |> > |>Might the sin function be written to give greater > |>accuracy for large real numbers? It seems that significant > |>digits are in some sense being discarded needlessly. > | > | > | Not really. The floating point representation of pi is not exact. The > problem > | only gets worse when you multiply it with something. The method you > showed of > | using % (2*pi) is only accurate when the values are created by > multiplying the > | same pi by another value. Otherwise, it just introduces another source > of error, > | I think. > | > | This is one of the few places where a version of trig functions that > directly > | operate on degrees are preferred. 360.0*n is exactly representable by > floating > | point arithmetic until n~=3D12509998964918 (give or take a power of > two). Doing % > | 360 can be done exactly. > > This reminds me of a story Richard Feynman tells in his autobiography. > He used to say: "if you can pose a mathematical question in 10 seconds, > I can solve it with 10% accuracy in one minute just calculating in my > head". This worked for a long time, until someone told him "please > calculate the sine of a million". > > Actual mantissa bits are used by the multiple of two-pi, and those are > lost at the back of the calculated value. Calculating the sine of a > million with the same precision as the sine of zero requires 20 more > bits of accuracy. > > Rob > - -- > Rob W.W. Hooft || ro...@ho... || http://www.hooft.net/people/rob/ > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.3 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFEdfziH7J/Cv8rb3QRAiO8AKCQdJ+9EMOP6bOmUX0NIhuWVoEFQgCgmvTS > fgO08dI16AUFcYKkpRJXg/Q=3D > =3DqQXI > -----END PGP SIGNATURE----- > > > ------------------------------------------------------- > All the advantages of Linux Managed Hosting--Without the Cost and Risk! > Fully trained technicians. The highest number of Red Hat certifications i= n > the hosting industry. Fanatical Support. Click to learn more > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D107521&bid=3D248729&dat= =3D121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |