1 import numpy as np
2 from math import *
3 def f(x):
4 return 3*x+sin(x)-exp(x)
5 xval=[]
6 funval=[]
7 kfirst=0.0; klast=2.0; kincrement=0.01
8 for j in np.arange(kfirst, klast + kincrement, kincrement):
9 xval.append(j)
10 funval.append(f(j))
11 import matplotlib.pyplot as plt
12 plt.title('$f(x)=3x+sin(x)-e^x$')
13 plt.xlabel('X Value')
14 plt.ylabel('Function Value')
15 plt.plot(xval, funval, '-')
16 plt.grid()
17 plt.savefig('function_plot.eps')
18 plt.show()
|
|