Exercise 1

This exercise requires you to plot a few functions in Python.

  1. Plot any three functions of your choosing of the form $y=f(x)$. $x$ should be an array of equally spaced numbers generated using the numpy linspace command (see numpy.linspace()). Be sure to include a legend and label the $x$ and $y$ axes.
  2. Use numpy to draw $N$ samples (you choose $N$) from a probability distribution of your choosing. See Random sampling for a bunch of numpy functions that draw random samples for you. See Statistical functions for an alternative to numpy. Plot a histogram of the data you generated.

In [35]:
import matplotlib.pyplot as plt
import numpy as np
x=np.linspace(0,10,num=10)
y=[a*a for a in x]
z=[a*a*a for a in x]
w=[a+a for a in x]
plt.plot(x,y,'r')
plt.ylabel("x^2")
plt.xlabel("x")

plt.plot(x,z,'g')
plt.ylabel("x^3")
plt.xlabel("x")

plt.plot(x,w,'b')
plt.ylabel("x*2")
plt.xlabel("x")
plt.legend([r"y=$x^2$",r"y=$x^3$",r"y=$x*2$"])

plt.show()



In [26]:
n_array=np.random.randn(100)
plt.hist(n_array,bins=10)
plt.show()



In [ ]:


In [ ]: