Source code for cubic_spline_integration
[docs]def x2_to_x3_integral(
x1,
x2,
x3,
x4,
f1,
f2,
f3,
f4,
):
h = x3 - x2
hm = x2 - x1
hp = x4 - x3
q1 = -hm / h
q4 = 1 + hp / h
avg_f = (
6 * q1 ** 3 * q4 ** 2 * (f2 + f3)
- 4 * q1 ** 3 * q4 * (2 * f2 + f3)
+ 2 * q1 ** 3 * (f2 - f4)
- 6 * q1 ** 2 * q4 ** 3 * (f2 + f3)
+ 3 * q1 ** 2 * q4 * (3 * f2 + f3)
+ 3 * q1 ** 2 * (-f2 + f4)
+ 4 * q1 * q4 ** 3 * (2 * f2 + f3)
- 3 * q1 * q4 ** 2 * (3 * f2 + f3)
+ q1 * (f2 - f4)
+ 2 * q4 ** 3 * (f1 - f2)
+ 3 * q4 ** 2 * (-f1 + f2)
+ q4 * (f1 - f2)
) / (
12 * q1 * q4 * (q1 - 1) * (q1 - q4) * (q4 - 1)
)
return avg_f * h
from scipy import integrate
print(f"exact: {exact}")
print(f"approx: {approx}")