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... 

 

> ? RiemannSum
 

Let's compute the right hand rule approximation of  int(cos(x), x = `+`(`-`(Pi)) .. `+`(`*`(2, `*`(Pi))))  using n = 10 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);
 

`+`(`*`(`/`(3, 10), `*`(Pi))) (1)
 

> evalf(RiemannSum(cos(x), x=-Pi..2*Pi, method = right, partition=10));
 

.9424777962 (2)
 

> Int(cos(x),x=-Pi..2*Pi) = evalf(int(cos(x),x=-Pi..2*Pi));
 

Int(cos(x), x = `+`(`-`(Pi)) .. `+`(`*`(2, `*`(Pi)))) = 0. (3)
 

> RiemannSum(cos(x), x=-Pi..2*Pi, method = right, output = plot, partition=10);
 

Plot_2d
 

 

Let's compute the left hand rule approximation of  int(sin(`*`(`^`(x, 2))), x = 0 .. 1)  using n = 5 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);
 

`+`(`*`(`/`(1, 5), `*`(sin(`/`(1, 25)))), `*`(`/`(1, 5), `*`(sin(`/`(4, 25)))), `*`(`/`(1, 5), `*`(sin(`/`(9, 25)))), `*`(`/`(1, 5), `*`(sin(`/`(16, 25))))) (4)
 

> evalf(RiemannSum(sin(x^2), x=0..1, method = left, partition=5));
 

.2297554431 (5)
 

> Int(sin(x^2),x=0..1) = evalf(int(sin(x^2),x=0..1));
 

Int(sin(`*`(`^`(x, 2))), x = 0 .. 1) = .3102683013 (6)
 

> RiemannSum(sin(x^2), x=0..1, method = left, output = plot, partition=5);
 

Plot_2d
 

 

Let compute the midpoint rule approximation of  int(exp(`+`(`-`(`*`(`^`(x, 2))))), x = -2 .. 2)  using n = 10 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);
 

`+`(`*`(`/`(4, 5), `*`(exp(-`/`(81, 25)))), `*`(`/`(4, 5), `*`(exp(-`/`(49, 25)))), `*`(`/`(4, 5), `*`(exp(-1))), `*`(`/`(4, 5), `*`(exp(-`/`(9, 25)))), `*`(`/`(4, 5), `*`(exp(-`/`(1, 25))))) (7)
 

> evalf(RiemannSum(exp(-x^2), x=-2..2, method = midpoint, partition=10));
 

1.765094018 (8)
 

> Int(exp(-x^2),x=-2..2) = evalf(int(exp(-x^2),x=-2..2));
 

Int(exp(`+`(`-`(`*`(`^`(x, 2))))), x = -2 .. 2) = 1.764162782 (9)
 

> RiemannSum(exp(-x^2), x=-2..2, method = midpoint, output = sum, partition=10);
 

`+`(`*`(`/`(2, 5), `*`(Sum(exp(`+`(`-`(`*`(`^`(`+`(`-`(`/`(9, 5)), `*`(`/`(2, 5), `*`(i))), 2))))), i = 0 .. 9)))) (10)
 

> RiemannSum(exp(-x^2), x=-2..2, method = midpoint, output = plot, partition=10);
 

Plot_2d
 

 

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]);
 

Plot_2d