Consider the polynomial $$ x^3 - 21 x^2 + 120 x - 100 = 0 $$ The roots are 1, 10, 10.
from sympy import N, roots
from sympy import Integer as Int
r = roots([1,-21,120,-100])
print('Roots = ',r)
for x in r:
print(x)
Roots = {1: 1, 10: 2} 1 10
The output shows that the root 1 has multiplicity one and root 10 has multiplicity of two.
Note: The type of return value r
is dict
.
Perturb the coefficient of $x^3$ $$ \frac{99}{100}x^3 - 21 x^2 + 120 x - 100 = 0 $$
r = roots([Int(99)/100,-21,120,-100])
for x in r:
print(N(x))
1.0001235059284 - 0.e-22*I 11.1706986297466 - 0.e-22*I 9.0412990764462 + 0.e-22*I
The double roots are very sensitive. Now perturb the coefficient in the other direction $$ \frac{101}{100}x^3 - 21 x^2 + 120 x - 100 = 0 $$
r = roots([Int(101)/100,-21,120,-100])
for x in r:
print(N(x))
0.999876592295142 9.89610130781283 - 1.04369535224477*I 9.89610130781283 + 1.04369535224477*I
The double roots become complex, again showing they are very sensitive to the coefficient of $x^3$.