plot function with large interval values

47 Views Asked by At

I'm trying to plot |sin(x)|/x in range x=[1e27,1e33].

x=np.logspace(27,33,1000000)
plt.plot(abs(np.sin(x))/x)
plt.xscale('log')

The answer has to be a smooth damping oscillator but this is what I get: enter image description here

I guess this is because of the large numbers I'm working with, any suggestions ?

1

There are 1 best solutions below

1
Davide_sd On

In plt.plot(abs(np.sin(x))/x) you only specified the y-coordinates, hence matplotlib used integers for the x-coordinates. Since you have 1000000 x-points, matplotlib x-axis goes from 0 to 1e06.

Try this:

plt.plot(x, abs(np.sin(x))/x)