You will write three functions for the Maclaurin series of the sine, , and use the alternating series bound to decide how many terms you need.
The idea. The th nonzero term (counting from ) is . If you keep terms terms, the first omitted term has terms, and the error is at most its size.
Your tasks.
sin_poly(x, terms). Return the sum of the first terms nonzero terms.alt_bound(x, terms). Return the size of the first omitted term, abs(x) ** (2 * terms + 1) / factorial(2 * terms + 1).terms_needed(x, tol). Return the smallest number of terms for which alt_bound(x, terms) is below tol.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…