#!/usr/bin/env python # coding: utf-8 # # Sensitivity of polynomial roots # Consider the polynomial # $$ # x^3 - 21 x^2 + 120 x - 100 = 0 # $$ # The roots are 1, 10, 10. # In[18]: from sympy import N, roots from sympy import Integer as Int # In[19]: r = roots([1,-21,120,-100]) print('Roots = ',r) for x in r: print(x) # 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 # $$ # In[20]: r = roots([Int(99)/100,-21,120,-100]) for x in r: print(N(x)) # 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 # $$ # In[21]: r = roots([Int(101)/100,-21,120,-100]) for x in r: print(N(x)) # The double roots become complex, again showing they are very sensitive to the coefficient of $x^3$.