CoCalc Public FilesPM_2_5 / wave_equation / worksheets / Integral_test.sagewsOpen in CoCalc with one click!
Authors: Mani Chandra, Balavarun P
%typeset_mode False from scipy import special as sp from scipy import integrate from sage.symbolic.integration.integral import indefinite_integral from sage.symbolic.integration.integral import definite_integral import numpy as np import math
# The error for numerical integration is 0.0034 numerical_integral(9.096e12 * x ** 58, -1, 1)
(308338983050.84705, 0.0034232503837255627)
# Definite integral and then applying limits sage_integral = definite_integral(9.096e12 * x**58, x, -1, 1) print(sage_integral)
308338983050.8475
poly_x = np.poly1d([1, 0]) poly_y = np.poly1d([1, 0])
for i in range(0,57): poly_x = poly_x * poly_y
print(poly_x)
58 1 x
poly1d_integral = np.poly1d.integ(9.096e12 * poly_x)(1) - np.poly1d.integ(9.096e12 * poly_x)(-1) print(poly1d_integral - numerical_integral(9.096e12 * x ** 58, -1, 1)[0])
0.00042724609375
print((sage_integral- poly1d_integral) * 1e14)
0.0