You will write three functions that add a geometric series by computer and compare the partial sums with the sum to infinity. A geometric series has a first term a and a common ratio r.
The idea. The partial sum S_N adds the first N terms a, a*r, a*r**2, and so on. When the size of r is less than , the sums settle on . Otherwise the series diverges.
Your tasks.
partial_sum(a, r, N). Add the first N terms with a loop.sum_to_infinity(a, r). Return a / (1 - r) when abs(r) < 1, and None otherwise.terms_needed(a, r, tolerance). Return the smallest N for which the partial sum is within tolerance of the sum to infinity.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…