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. /Least values by search and by AM-GM
MathematicsMediumHigh School (11–12)Inequalities and the AM, GM and HM Means

Least values by search and by AM-GM

You will find the least value of f(x)=x2+kxf(x) = x^2 + \dfrac{k}{x}f(x)=x2+xk​ for x>0x > 0x>0 in two ways: by a search on a grid, and by the AM-GM formula. The checker compares the two for several values of kkk.

The idea. Splitting kx\dfrac{k}{x}xk​ into two halves gives x2+k2x+k2x≥3k243x^2 + \dfrac{k}{2x} + \dfrac{k}{2x} \ge 3\sqrt[3]{\dfrac{k^2}{4}}x2+2xk​+2xk​≥334k2​​, with equality at x=k23x = \sqrt[3]{\dfrac{k}{2}}x=32k​​.

Your tasks.

  1. Finish grid_min(f, lo, hi, steps). Try steps + 1 equally spaced values of xxx from lo to hi, and return the smallest value of f(x).
  2. Finish amgm_bound(k). Return 3 * (k * k / 4) ** (1 / 3).
  3. Finish best_x(k), the point of equality, (k / 2) ** (1 / 3).

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, call grid_min with lo = 4 for k = 16. Why is the answer larger than amgm_bound(16)?

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
← Three means and their orderTesting Cauchy-Schwarz →
More onInequalities and the AM, GM and HM Means

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Greatest and least values with the meansThe AM-GM-HM Inequality and Power Means

More labs on this topic

  1. The point that minimises total distanceMedium
  2. Convexity on a gridMedium
  3. Best and worst pairingsMedium
  4. Testing Cauchy-SchwarzMedium
Three means and their orderMedium
All labs on this topic →