I've come across an issue where if I multiply the input of numpy.sin()
by pi it outputs a strange graph that in no way approximates the actual result. If I round pi to 3.14 it works, but any decimal places up to and including np.pi breaks it. Can anyone tell me what's causing this?
This is my code:
lim = 4096
x = np.arange(0,lim)
y = np.sin(2*np.pi*x)
plt.plot(x,y)
plt.show()
This is the output of the plot using np.pi
, this is using 3.14159265, this is using 3.141, this is using 3.14. As you can see, the amplitude is also screwy, being on the order of -12 for np.pi
, -5 for 3.14159265, etc. What's going on?
np.sin(x)
expects x
to be in radians, not degrees.
2*np.pi*x
in radians is almost precisely an integer multiple of 360 degrees. Its sine is very close to 0, and that is what you see in the first plot.
3.14159265, etc. are even more different from the real Pi than np.pi
, that is why you start seeing bigger y
's. The reason why your plots look like sine waves is because of sampling.