Polynomial synthetic division: Difference between revisions
Content deleted Content added
m →{{header|Python}}: ahora funciona en Python 2.7 y 3.x |
|||
Line 579: | Line 579: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
Here is an extended synthetic division algorithm, which means that it supports a divisor polynomial (instead of just a monomial/binomial). It also supports non-monic polynomials (polynomials which first coefficient is different than 1). Polynomials are represented by lists of coefficients with decreasing degree (left-most is the major degree , right-most is the constant). |
Here is an extended synthetic division algorithm, which means that it supports a divisor polynomial (instead of just a monomial/binomial). It also supports non-monic polynomials (polynomials which first coefficient is different than 1). Polynomials are represented by lists of coefficients with decreasing degree (left-most is the major degree , right-most is the constant). |
||
{{works with|Python 2. |
{{works with|Python 2.7}} |
||
{{works with|Python 3.x}} |
|||
<lang python># -*- coding: utf-8 -*- |
|||
<lang python>from __future__ import print_function |
|||
from __future__ import division |
|||
#!/usr/bin/python |
|||
# coding=UTF-8 |
|||
def extended_synthetic_division(dividend, divisor): |
def extended_synthetic_division(dividend, divisor): |
||
Line 604: | Line 609: | ||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
print |
print("POLYNOMIAL SYNTHETIC DIVISION") |
||
N = [1, -12, 0, -42] |
N = [1, -12, 0, -42] |
||
D = [1, -3] |
D = [1, -3] |
||
print |
print(" %s / %s =" % (N,D), " %s remainder %s" % extended_synthetic_division(N, D)) |
||
print " %s remainder %s" % extended_synthetic_division(N, D) |
|||
</lang> |
</lang> |
||
Line 614: | Line 618: | ||
<pre> |
<pre> |
||
POLYNOMIAL SYNTHETIC DIVISION |
POLYNOMIAL SYNTHETIC DIVISION |
||
[1, -12, 0, -42] / [1, -3] = [1, -9, -27] remainder [-123] |
[1, -12, 0, -42] / [1, -3] = [1, -9, -27] remainder [-123] |
||
</pre> |
</pre> |
||