{ "metadata": { "name": "", "signature": "sha256:30b2dd95d65b098198f30d30db780b094899accf00b2803ab4f8fec6ef648297" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Sensitivity of polynomial roots" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Consider the polynomial\n", "$$\n", "x^3 - 21 x^2 + 120 x - 100 = 0\n", "$$\n", "The roots are 1, 10, 10." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sympy import N, roots\n", "from sympy import Integer as Int" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "r= roots([1,-21,120,-100])\n", "for x in r:\n", " print x" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1\n", "10\n" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Perturb the coefficient of $x^3$ \n", "$$\n", "\\frac{99}{100}x^3 - 21 x^2 + 120 x - 100 = 0\n", "$$" ] }, { "cell_type": "code", "collapsed": false, "input": [ "r= roots([Int(99)/100,-21,120,-100])\n", "for x in r:\n", " print N(x)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1.0001235059284 + 0.e-20*I\n", "9.0412990764462 + 0.e-20*I\n", "11.1706986297466 + 0.e-20*I\n" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The double roots are very sensitive. Now perturb the coefficient in the other direction\n", "$$\n", "\\frac{101}{100}x^3 - 21 x^2 + 120 x - 100 = 0\n", "$$" ] }, { "cell_type": "code", "collapsed": false, "input": [ "r= roots([Int(101)/100,-21,120,-100])\n", "for x in r:\n", " print N(x)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "9.89610130781283 + 1.04369535224477*I\n", "9.89610130781283 - 1.04369535224477*I\n", "0.999876592295142\n" ] } ], "prompt_number": 6 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The double roots become complex, again showing they are very sensitive to the coefficient of $x^3$." ] } ], "metadata": {} } ] }