Generate a Python visualization of Riemann sums

Goal

Test whether GenAI can help a teacher quickly create a small Python script that illustrates Riemann sums for a function of one variable.

Verification reminder. All mathematical claims, solutions, and code should be checked independently by a human.

Suggested task

  1. Choose a simple function, for example f(x) = x^2 on an interval such as [0,1].
  2. Ask the GenAI to write a Python script that plots the function and the associated rectangles.
  3. Ask for an option to switch between left, right, and midpoint sums.
  4. Discuss whether the code is correct, readable, and easy to adapt for teaching.

Example prompt

Write a short Python script using matplotlib and numpy that plots a 1D function together with its Riemann-sum rectangles on a given interval. Start with f(x) = x**2 on [0,1]. Include a parameter n for the number of subintervals and an option to choose left, right, or midpoint Riemann sums. Keep the code simple enough for first-year university students.

Questions for the group

  • Is the mathematical interpretation of the rectangles correct?
  • Is the code readable enough to use in class or share with students?
  • What errors or omissions would a teacher need to fix?
  • Could this be extended to animations, comparisons, or student exercises?

Minimum output expected from the group

  • One part of the code that was immediately usable
  • One mathematical or programming correction that was needed
  • One possible classroom extension