Lab 14: Riemann Sums¶
In this lab we will study Riemann sums in higher dimensions.
Task 1¶
Write a function riemann_sum_1D
which takes 5 parameters f
, xMin
, xMax
, N
, and method
and returns the Riemann sum
where Δx = (xMax - xMin)/N
and method
determines whether we are using the lower left, upper right, or midpoints of the partition. (The options for the method should be "left"
, "right"
, "mid"
).
Task 2¶
Write a function riemann_sum_2D
which takes 7 parameters f
, xMin
, xMax
, yMin
,
yMax
, N
, and method
and returns the Riemann sum
where Δx = (xMax - xMin)/N
, Δy = (yMax - yMin)/N
and method
determines whether we are using the lower left, upper right, or midpoints of the partition. (The options for the method should be "left"
, "right"
, "mid"
). (Hint: you can copy much of the code you wrote for Task 1)
Task 3¶
Consider the integral of \(f(x, y) = x \sin(x + y)\) on the rectangle \([0, \pi/6] \times [0, \pi/3]\). First calculate the exact value of this integral by hand. Then make a plot that shows the error of the midpoint Riemann integral approximation as \(N\) ranges from \(1\) to \(100\).
Task 4¶
Write a function riemann_sum_3D
which takes 9
parameters f
, xMin
, xMax
, yMin
, yMax
, zMin
, zMax
, N
, and method
and returns the Riemann sum
where Δx = (xMax - xMin)/N
, Δy = (yMax - yMin)/N
, Δz = (zMax - zMin)/N
and method
determines whether we are using the lower left, upper right, or midpoints of the partition. (Hint: you can copy much of the code you wrote for Task 2)
Task 5¶
Description: Write a function, riemann_sum(f, x_min, x_max, N, method)
, that takes as input a function of an n-dimensional variable (x
), f
, a vector of minimum values of the components of x
, x_min
, a vector of maximum values of the components of x
, x_max
, a number of sub-intervals to compute, N
, and Riemann method to use, method
("left"
, "right"
, "mid"
).