You will write three small functions that estimate the length of a curve. The program joins points of the curve by straight pieces, adds the lengths, and counts how many pieces give a chosen accuracy. The checker uses a line and the curve .
The idea. One straight piece from to has length . Cut into equal steps and add the lengths of the pieces. More pieces give a better estimate.
Your tasks.
piece_length(x1, y1, x2, y2). Return the length of the straight piece.curve_length(f, a, b, n). Join the points of f at x = a, a + h, ..., b by straight pieces, with h = (b - a) / n, and return the total length.pieces_needed(f, a, b, exact, tol). Try n = 1, 2, 4, 8, ... and return the first n whose estimate is within tol of exact.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…