[Numpy-discussion] what goes wrong with cos(), sin()
Charles R Harris
Wed Feb 21 12:25:50 CST 2007
On 2/21/07, WolfgangZillig <email@example.com> wrote:
> I'm quite new to numpy/scipy so please excuse if my problem is too
> example code:
> import numpy as n
> print n.sin(n.pi)
> print n.cos(n.pi/2.0)
> results in:
> I've expected something around 0. Can anybody explain what I am doing
> wrong here?
They *are* around zero. You are seeing rounding error, probably both in the
value of pi and the approximations used to evaluate the sin and cos, most
likely some rational min/max fit. I recall teaching PDEs to students who
used Mathematica and they had the same sort of problem because terms
involving sin(pi) didn't go exactly to zero. Made their fourier series not
quite match the text answers. If you want these sort of terms to be exact
you will have to use some sort of symbolic program.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion