7.1
import numpy as np
from scipy.interpolate import interp1d
from scipy.integrate import quad
import matplotlib.pyplot as plt
g = lambda x: (3 * x ** 2 + 4 * x + 6) * np.sin(x) / (x ** 2 + 8 * x + 6)
x0 = np.linspace(0, 10, 1000)
y0 = g(x0)
gh = interp1d(x0, y0, 'cubic')
xn = np.linspace(0, 10, 10000)
yn = gh(xn)
Il = quad(g, 0, 10)
I2 = np.trapz(yn, xn)
print('Il =', Il)
print('I2 =', I2)
plt.rc('font', family='SimHei')
plt.rc('axes', unicode_minus=False)
plt.plot(x0, y0, '*-', label='原来函数')
plt.plot(xn, yn, '.-', label='插值函数')
plt.legend()
plt.show()
print("学号后四位:3022")