import numpy as np
import scipy.interpolate as spi
import scipy.integrate as spi_integrate
def g(x):
return ((3x**2 + 4x + 6) * np.sin(x)) / (x**2 + 8*x + 6)
x_values = np.linspace(0, 10, 1000)
y_values = g(x_values)
spline = spi.CubicSpline(x_values, y_values)
def h(x):
return spline(x)
integral_g, _ = spi_integrate.quad(g, 0, 10)
x_fine = np.linspace(0, 10, 10000)
y_fine = h(x_fine)
integral_h = np.trapz(y_fine, x_fine)
print(f"积分 g(x) 从 0 到 10 的结果: {integral_g}")
print(f"积分 h(x) 从 0 到 10 的结果: {integral_h}")
print("学号后四位:3004")
标签:10,Xi,values,np,fine,1000 From: https://www.cnblogs.com/howoo0808/p/18513074