You will write three small functions for the equation . The first finds the two roots of the auxiliary equation. The second names the case. The third tests a function in the equation.
The idea. The roots of are . The sign of names the case. A function solves the equation when is zero. The first and second derivatives can be estimated from nearby values.
Your tasks.
roots(a, b, c). Return the pair of roots, using cmath.sqrt so that complex roots work too.case_of(a, b, c). Return "real" when , "equal" when it is within 0.000001 of zero, and "complex" otherwise.residual(y, a, b, c, x). Return at x, with the slope from (y(x + h) - y(x - h)) / (2 * h) and the second derivative from (y(x + h) - 2 * y(x) + y(x - h)) / h ** 2, where h = H.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…