2.2.2 Riemann and trapezoid sums for integrals

Regarding numerical approximation of $ \int_a^bf(x)\, dx$ , where $ f$ is a piecewise defined function, Sage can

 
sage: f1 = x^2      
sage: f2 = 5-x^2
sage: f = Piecewise([[(0,1),f1],[(1,2),f2]])
sage: f.trapezoid(4)
Piecewise defined function with 4 parts, [[(0, 1/2), x/2], 
[(1/2, 1), 9*(x - 1/2)/2 + 1/4], [(1, 3/2), (x - 1)/2 + 5/2], 
[(3/2, 2), 11/4 - 7*(x - 3/2)/2]]
sage: f.riemann_sum_integral_approximation(6,mode="right")
19/6
sage: f.integral()
3

See About this document... for information on suggesting changes.