Plotting cosine with Python
Question: I plot a cosine sampled at 400 points in the interval -5 .. +5 using python
for n=1..4:

    
    
    import matplotlib.pyplot as plt
    import numpy
    
    for n in range(1,5):
        x = numpy.linspace(-5,5,num=400)
        series = numpy.cos(1e4/n*x)
        plt.figure()
        plt.plot(series)
    

But for n = 3 the plot looks not like a cosine which I think is due to
sampling error. How can I achieve a smooth cosine plot with constant samples
for different frequencies (i.e. different n)?


Answer: Change your calculation to `series = numpy.cos(2*numpy.pi/n*x)`.

Multiplying by `1e4` means you have fewer than 2 points per cycle of your
cosine, thus causing [aliasing](http://en.wikipedia.org/wiki/Aliasing).

