You will write a tester for identities. It measures the largest gap between two functions on an interval, decides whether they agree, and finds the widest interval around from a list on which they agree. The checker uses it on three identities from the lesson.
The idea. An identity is true on an interval when the two sides are equal at every point. A computer cannot try every point, but a fine grid of points shows a failure at once. The gap between two functions at a point is the absolute value of their difference.
Your tasks.
max_gap(f, g, xs). Return the largest value of abs(f(x) - g(x)) over the numbers in xs.holds(f, g, a, b). Use equally spaced points from a to b. Return True if the largest gap is below 1e-9.largest_k(f, g, ks). Go through the numbers k in the list ks. Return the largest k for which the identity holds on , or None if there is none.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 join the discussion.
Loading…
With Standard, you also open 12 more problems, 2 Python labs and 1 extra course. Everything you have used here stays free, always.