def Quadratic(x):
"""定义二次函数"""
return 2 * x ** 2 + 3 * x + 4
x = np.linspace(-5, 5, 30) # 将积分区间30等分
print(x)
y = Quadratic(x)
print(y)
plt.plot(x, y) # 绘制函数曲线
plt.plot(x, [0]*len(x), color="b")
for i in range(len(x)): # 绘制x轴
plt.plot([x[i], x[i]], [0, y[i]]) # 绘制梯形的上底和下底
for i in range(len(x) - 1):
plt.plot([x[i], x[i + 1]], [y[i], y[i + 1]]) # 将梯形的斜腰连起来
plt.show()