In: Computer Science
Plot the functions x, x2, exp(-x),
exp(-x2) on four different graphs (two rows and two
columns) between 0 and 5 in python
Here is the answer...
CODE:
import numpy as np
import matplotlib.pyplot as plt
pos_array = np.arange(0, 5, 0.1)
#creating x between 0 to 5 with range 0.1
neg_array = [-i for i in pos_array] # -x
exp_array = np.exp(neg_array) #exp(-x)
sq_array = [-i*i for i in pos_array] #-x^2
#print(sq_array)
exp_sq_array = np.exp(sq_array) #exp(-x^2)
#print(exp_sq_array)
fig = plt.figure()
ax1 = fig.add_subplot(2, 2, 1)
ax1.title.set_text('x')
ax1.plot(pos_array)
ax2 = fig.add_subplot(2, 2, 2)
ax2.title.set_text('-x')
ax2.plot(neg_array)
ax3 = fig.add_subplot(2, 2, 3)
ax3.title.set_text('exp(-x)')
ax3.plot(exp_array)
ax4 = fig.add_subplot(2, 2, 4)
ax4.title.set_text('exp(-x2)')
ax4.plot(exp_sq_array)
plt.show()
CODE Snapshot:
if you have any doubts please COMMENT.....
If you understand the answer please give THUMBS UP....