Let's start by using Sage functions to numerically integrate a symbolic function of one variable:
var('x') f(x) = e^x * cos(x) f.show() a = 0 b = 8 p = plot(f, (x, a, b)) p.show(figsize=(4, 3)) print("Integral of f(x) from {0} to {1}:".format(a,b)) print(" Analytical definite integral: {0}" .format(f.integral(x, a, b).n())) integral_value, tolerance, num_evals, error_code = \ f.nintegral(x, a, b) print(" Using nintegral: {0}".format(integral_value)) # also nintegrate integral_value, tolerance = numerical_integral(f, a, b) print(" Using numerical_integral: {0}".format(integral_value))
A plot of the function, along with the integration results, is shown below: