Riemann Sums in Maple
Source: math1110-summer2014-riemann_sums.mw
> |
# Load the Calculus1 subpackage of the Student package.
# This contains the "RiemannSum" command that we'll use.
with(Student[Calculus1]): |
For more details about the RiemannSum command check out Maple's help...
Let's compute the right hand rule approximation of using rectangles. Then we'll find a decimal approximation of this sum and Maple's approximation of the integral.
> |
RiemannSum(cos(x), x=-Pi..2*Pi, method = right, partition=10); |
|
(1) |
> |
evalf(RiemannSum(cos(x), x=-Pi..2*Pi, method = right, partition=10)); |
|
(2) |
> |
Int(cos(x),x=-Pi..2*Pi) = evalf(int(cos(x),x=-Pi..2*Pi)); |
|
(3) |
> |
RiemannSum(cos(x), x=-Pi..2*Pi, method = right, output = plot, partition=10); |
Let's compute the left hand rule approximation of using rectangles. Then we'll find a decimal approximation of this sum and Maple's approximation of the integral.
> |
RiemannSum(sin(x^2), x=0..1, method = left, partition=5); |
|
(4) |
> |
evalf(RiemannSum(sin(x^2), x=0..1, method = left, partition=5)); |
|
(5) |
> |
Int(sin(x^2),x=0..1) = evalf(int(sin(x^2),x=0..1)); |
|
(6) |
> |
RiemannSum(sin(x^2), x=0..1, method = left, output = plot, partition=5); |
Let compute the midpoint rule approximation of using rectangles. We'll also find Maple's approximation and make the RiemannSum command display the sum in summation notation and make a nice plot.
> |
RiemannSum(exp(-x^2), x=-2..2, method = midpoint, partition=10); |
|
(7) |
> |
evalf(RiemannSum(exp(-x^2), x=-2..2, method = midpoint, partition=10)); |
|
(8) |
> |
Int(exp(-x^2),x=-2..2) = evalf(int(exp(-x^2),x=-2..2)); |
|
(9) |
> |
RiemannSum(exp(-x^2), x=-2..2, method = midpoint, output = sum, partition=10); |
|
(10) |
> |
RiemannSum(exp(-x^2), x=-2..2, method = midpoint, output = plot, partition=10); |
Maple will also allow non-uniform partitions...
> |
RiemannSum(x^2, x=-2..4, method = left, output = plot, partition=[-2,0,1,1.5,2,2.5,3,4]); |