Skip to content

Instantly share code, notes, and snippets.

@vr2262
Created May 6, 2013 01:34
Show Gist options
  • Save vr2262/5522894 to your computer and use it in GitHub Desktop.
Save vr2262/5522894 to your computer and use it in GitHub Desktop.
def ruffinis_rule(coefficients, factor):
"""Perform synthetic division and evaluate a polynomial at a factor."""
deflated = np.empty(len(coefficients) - 1, dtype=complex)
deflated[0] = coefficients[0]
for i, coeff in enumerate(coefficients[1:-1], start=1):
deflated[i] = coeff + deflated[i - 1] * factor
evaluation = coefficients[-1] + deflated[-1] * factor
return deflated, evaluation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment