HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /Trapezium and mid-ordinate rules
MathematicsHardHigh School (11–12)Numerical Methods

Trapezium and mid-ordinate rules

You will write the two strip rules as functions of f, a, b and the number of strips n.

The idea. Tn=h2[f(a)+f(b)+2(inner values)]T_n = \tfrac{h}{2}\big[f(a) + f(b) + 2(\text{inner values})\big]Tn​=2h​[f(a)+f(b)+2(inner values)] and Mn=h×M_n = h \timesMn​=h× (sum of fff at the midpoints), with h=b−anh = \dfrac{b - a}{n}h=nb−a​.

Your tasks.

  1. Finish trapezium(f, a, b, n).
  2. Finish mid_ordinate(f, a, b, n).
  3. Finish shrink(f, a, b, n, exact). Return the ratio of the trapezium error with n strips to the error with 2 * n strips.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, print shrink(math.sqrt, 0, 1, 4, 2 / 3). Why is it not close to 4? Look at the curve near 0.

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← A careful Newton solverSimpson's rule and Richardson's trick →
More onNumerical Methods

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. The trapezium and mid-ordinate rulesNumerical Integration and Hyperbolic Substitutions

More labs on this topic

  1. Simpson's rule and Richardson's trickHard
  2. A careful Newton solverHard
  3. A bisection solverHard
All labs on this topic →