jueves, 5 de octubre de 2017

Polyniomial Roots - QR algorithm in 1961 - John Francis

http://www.math.cornell.edu/~web6140/TopTenAlgorithms/QRalgorithm.html


The QR algorithm

The QR algorithm is the algorithm employed for the last 50 years for computing eigenvalues and eigenvectors.

Before 1961

Before 1961, one bad way to compute eigenvalues of a matrix A
was to calculate the roots of the characteristic polynomial, i.e., find the zeros of
p(x)=det(A−xI),
where I is the identity matrix. The accuracy of this approach depends on the basis employed for the polynomial as well the eigenstructure of A. For example, a semisimple eigenvalue of A (that should be computed to full accuracy) becomes a root of p with multiplicity >1
(that cannot be computed accurately in floating point). Finding eigenvalues of matrices via roots of polynomials is --- regardless of the algorithmic details --- a numerically unstable eigensolver.
# Find eigenvalues of $A$ via roots of the characteristic polynomial:
using Polynomials 
n = 10
A = randn(n,n) 
p(x) = det(A-x*eye(n))
x = collect(linspace(-1,1,n+1))
cfs = polyfit(x, map(p,x))
norm( sort(real(roots(cfs))) - sort(real(eigvals(A))), Inf)
2.2829160783999214e-10

The unshifted QR algorithm

John Francis' idea in 1961 for computing the eigenvalues of A
is (without any bells or whistles) surprisingly simple. We will refer to this as the unshifted QR algorithm. It looks like this:
Set A0=A,for k = 1,2,... (until convergence)Compute Ak−1=QkRkSet Ak=RkQkend
That is, compute the QR factorization of A
, then reverse the factors, then compute the QR factorization of the result, before reversing the factors, and so on.
It turns out that the sequence A0,A1,…,
have the same eigenvalues and for any large integer K the matrix AK is usually close to being upper-triangular. Since the eigenvalues of an upper-triangular matrix lie on its diagonal, the iteration above will allow us to read off the eigenvalues of A from the diagonal entries of AK. Once we have the eigenvalues, the eigenvectors can be computed, for example, by an inverse power iteration.
For example, below we take a random 100×100
matrix and plot the sparsity pattern of the matrix A1000
.
# unshift QR algorithm:
using PyPlot
A = rand(100,100); 

for k = 1:1000
    (Q,R) = qr(A)
    A = R*Q
end
spy(abs(A).>1e-4)
PyObject <matplotlib.image.AxesImage object at 0x31f497dd0>
After 1000
steps we find that A1000 is nearly, but not quite, upper-triangular. After another 1000 iterations, or so, this example will converge to upper-triangular so we can read off the eigenvalues.

A word of warning

The sequence A0,A1,…,
computed by the unshifted QR algorithm above does not always converge. For example, consider the matrix
A=A0=[0110].
In this example, Ak=A0 for all k
and the unshift QR algorithm is stagnate. Below, we will fix that with Wilkinson shifts. (Note that Rayleigh quotient shifts do not fix this example.)

Why does the sequence A0,A1,…,

have the same eigenvalues?

Answer: Similar matrices. Two matrices A
and B are similar if there exists an invertible matrix S so that A=S−1BS. Similar matrices have the same eigenvalues:
Av–=λv–⇔B(S−1v–)=λ(S−1v–).
The iterates A0,A1,…, from the QR algorithm are similar matrices since
Ak+1=RkQk=Q−1kQkRkQk=Q−1kAKQk.
Therefore, A0,A1,…,
have the same eigenvalues.
A = rand(10,10)
A0 = A
e0 = eigvals(A0)   # Eigenvalues of original matrix
(Q,R) = qr(A0)
e1 = eigvals(R*Q)  # Eigenvalues of A_1
# Same real and imag part:
norm( sort(real(e0)) - sort(real(e1)) ), norm( sort(imag(e0)) - sort(imag(e1)) )
(2.2760418195658854e-15,9.550499576785472e-16)

Why does the sequence A0,A1,…,

usually converge to an upper-triangular matrix?

The secret to why the QR algorithm produces iterates that usually converge to reveal the eigenvalues is from the fact that the algorithm is a well-disguised (successive) power method. A very first idea to calculate eigenvalues might be to perform the power iteration on a basis x−−1,…,x−−n
of Rn instead of just one vector. That is, to consider the sequences:
x−−j,Ax−−j,A2x−−j,….
Unfortunately, this does not work as the vectors Akx−−j
all tend to be close to a multiple of the eigenvector of A corresponding to the eigenvalue of largest magnitude. Moreover, ∥Akx−−j∥ usually overflows or underflows for moderate k. We can resolve the situation by orthonormalizing the vectors after each application of A to prevent them from all converging to the dominate eigenvector.

The QR algorithm based on Gram-Schmidt and the power iteration

Let x−−1,…,x−−n
be n linearly independent vectors in Rn and suppose that v1,…,vn are an orthonormal basis of Schur vectors for A (see wiki). Consider the following algorithm for computing the vectors v1,…,vn based on the Gram-Schmidt procedure and the power method:
u(1)0u(2)0u(2)0=u(2)0−⋮u(r)0u(r)0=u(r)0−=x−−1∥x−−1∥,u(1)1=Au(1)0∥Au(1)0∥,u(1)2=Au(1)1∥Au(1)1∥,…⟶±v–1=x−−2∥x−−2∥,u(2)1=Au(2)0∥Au(2)0∥,u(2)2=Au(2)1∥Au(2)1∥,…⟶±v–2v–T1u(2)0v–1,u(2)1=u(2)1−v–T1u(2)1v–1,⋮=x−−2∥x−−2∥,u(r)1=Au(r)0∥Au(r)0∥,u(r)2=Au(r)1∥Au(r)1∥,…⟶±v–r∑j=1r−1v–Tju(r)0v–j,u(r)1=u(r)1−∑j=1r−1v–Tju(r)1v–j,
While this algorithm will be far better than the power iteration without orthogonalization, this algorithm is still numerically unstable (as it is based on Gram-Schmidt). In particular, the computed vectors v–1,…,v–n
may not be orthonormal numerically. To try it out, we implement this algorithm below for symmetric matrices so that the Schur vectors are in fact eigenvalues:
function OrthogonalProjection( v::Vector, Q::Matrix )
   # Orthogonal projection 
    m = size(Q,2)
    for k = 1:m
        c = dot(Q[:,k], v)
        for j = 1:size(v,1)
            v[j] -= c*Q[j,k]
        end
    end
    return v
end

function OrthogonalPowerIteration( v::Vector, Q::Matrix )
   # Do Power iteration, while projecting:
    m = size(Q,2)
    for k = 1:1000
        v = OrthogonalProjection( A*v, Q )
        v = v/norm(v)
    end
    return v
end

function OrthogonalPowerIteration( v::Vector )
   # Do power iteration while projecting:
    for k = 1:1000
        v = A*v
        v = v/norm(v)
    end
    return v
end

function GramSchmidtBasedQRAlgorithm( A::Matrix )
    # Use Gram-Schmidt and power iteration to compute the eigenvalues of A:
    n = size(A,1)
    v = rand(n)
    Q = (OrthogonalPowerIteration( v )')'
    for k = 2:n
        v = rand( n )
        v = OrthogonalPowerIteration( v, Q )
        Q = hcat(Q, v)
    end
    return sort(mean((A*Q)./Q,1)[:],rev=false)
end
GramSchmidtBasedQRAlgorithm (generic function with 1 method)
Here, we test this code to witness the numerical instability:
# Random matrix: 
srand(1234)
A = rand(40,40)
A = A'*A
# True eigenvectors and eigenvalues.
(Λ,S) = eig( A )
# Compute eigenvalues of A via power iteration and Gram-Schmidt: 
λ = GramSchmidtBasedQRAlgorithm( A::Matrix )
norm( Λ - λ )
2.3313616336807864e-9

Orthogonal iteration

Of course, we can greatly improve the situation by using the modified Gram-Schmidt and the power method, where we do not wait for the vector v–1
before doing a power iteration for v–2. Instead, we do the power method simutaneously on every vector and orthogonalize after every step. A even better idea is to use Householder reflections for extra numerical stability. This gives us an algorithm called orthogonal iteration. The algorithm looks like this:
Set U(0)=[x1|⋯|xn],for k = 1,2,... (until convergence)Compute Q(k)R(k)=U(k−1)Set U(k)=AQ(k)end
The matrix iterates U(0),U(1),…,
here are computed so that (U(k))TAU(k)→T, where T
is upper-triangular.
function OrthogonalIteration( A::Matrix )
    # Orthogonal iteration on A:
    n = size(A,1)
    (Q,R) = qr(rand(n,n))
    for k = 1:10000
        (Q,R) = qr(A*Q)
    end
    return Q
end
OrthogonalIteration (generic function with 1 method)
# For orthogonal iteration U^TAU ---> triangular:  (This may not 
# always work because we don't have shifts...)
A = rand(3,3)
U = OrthogonalIteration( A )
triu(U'*A*U) ≈ U'*A*U
false

Orthogonal iteration to QR algorithm

One can view the QR algorithm as a well-designed version of orthogonal iteration with U(0)=I
. The connection can seen from the fact that they are both computing QR factorizations of the matrix Ak:
QR algorithmAkOrthogonal iterationAk=Q1R1Q1R1⋯Q1R1=Q1Q2R2Q1⋯Q1R1=⋯=(Q1⋯Qk)(Rk⋯R1)=AAk−1=AQ(k−1)(Q(k−1))TAk−1=Q(k)R(k)(Q(k−1))TAk−1=⋯=Q(k)(R(k)⋯R(1)).
John Francis' algorithm is computing Ak=QkRk
at the kth iteration, which is converging to an upper-triangular matrix. This is not too surprising because we expect Q1⋯Qk to converge to an orthogonal matrix so Qk should converge to the identity matrix and hence, QkRk will usually converge to an upper-triangular matrix. Since Ak=QkRk is similar to A, the eigenvalues of Rk should converge to the eigenvalues of A as k→∞. In this next section, we make this intuition precise.

A proof of convergence

Here, we prove the following convergence theorem with lots of assumption to make the proof as easy as possible. Afterwards, we write down two way to make the theorem strong.
Theorem: Let A
be an n×n symmetric positive definite matrix with distinct eigenvalues given by
λ1>λ2>⋯>λn>0.
Assume further that A=QΛQT is the eigenvalue decomposition of A, where QT=LU has an LU decomposition and the diagonal entries of U are nonnegative. Then, the unshift QR algorithm on A computes iterates A1,A2,A3,…, that converge to a diagonal matrix.
Proof For simplicity here we will start by assuming that every computed QR factorization of a matrix involves an upper-triangular matrix R
with nonnegative diagonal entries. This ensures that the QR factorization is unique (see class exercises). Let
A=QΛQT
be the eigenvalue decomposition for A. Then, Ak can be written as
Ak=QΛkQT=(Q1⋯Qk)(Rk⋯R1).
Since QT=LU exists by assumption (recall that L is unit lower triangular so has 1's on the diagonal), we find
QΛkLΛ−k=(Q1⋯Qk)(Rk⋯R1)U−1Λ−k.
Considering the matrix ΛkLΛ−k, we observe that
(ΛkLΛ−k)ij=⎧⎩⎨⎪⎪⎪⎪ℓij(λiλj)k,10,otherwisei>j,i=j,
so the matrix ΛkLΛ−k→I as k→∞. We conclude that QΛkLΛ−k→Q and (Q1⋯Qk)(Rk⋯R1)U−1Λ−k→Q. Since the QR factorization is unique (when the triangular matrix has nonnegative entries), we have Q1⋯Qk→Q and (Rk⋯R1)U−1Λ−k→I. Finally, we find that Qk→I and
QTk⋯QT1AQ1⋯Qk=Ak=QkRk→Λ,
where the last convergence results follows because Qk→I and QkRk is symmetric and similar to A.
There are two ways to improve the theorem above and the reader may like to try them:
  • Keep the assumption that QT=LU
exists, but remove the assumption that U
  • has nonnegative diagonal entries, and
    • is positive definite, but keep the assumption that every eigenvalue is distinct.

    Computational considerations

    While the basic QR algorithm can be used to compute eigenvalues it is (1) Computationally expensive (requiring O(n3)
    operations per iteration) and (2) Can have a painfully slow convergence depending on the eigenvalues of A. There are three ideas to improve the situation: (1) Reduce the matrix A to a similar matrix that is upper-Hessenberg (Hessenberg structure is preserved by the QR algorithm, see class exercises), which reduces the cost per iteration to O(n2) operations, (2) Once an eigenvalue has been computed deflate away this matrix, which greatly speeds up later eigenvalue computations, and (3) Use "shifts" in the QR algorithm.

    Reduction to a similar upper-Hessenberg matrix

    The idea here is reduce the matrix A
    to an upper-Hessenberg matrix H so that A and H have the same eigenvalues. We can do this by making sure that A and H are similar matrices. Our first step is to make the first column of A look like an upper-Hessenberg matrix. We use a Householder reflection for that (if a1 is the first column of A, then consider the Householder reflection for the vector a1(2:n)) and to ensure the resulting matrix is similar we apply the transpose of the Householder reflection on the right:
    QvAQTv=⎡⎣⎢⎢⎢⎢⎢⎢⎢∗∗∗∗∗⋮∗∗∗∗⋮∗………⋱…∗∗∗⋮∗⎤⎦⎥⎥⎥⎥⎥⎥⎥=B
    The process occurs recursively now on the (n−1)×(n−1) principle matrix obtained after deleting the first row and column. The sequence of similar matrices looks like this:
    ⎡⎣⎢⎢⎢⎢⎢⎢⎢∗∗∗⋮∗∗∗∗⋮∗∗∗∗⋮∗………⋱…∗∗∗⋮∗⎤⎦⎥⎥⎥⎥⎥⎥⎥→⎡⎣⎢⎢⎢⎢⎢⎢⎢∗∗∗∗∗⋮∗∗∗∗⋮∗………⋱…∗∗∗⋮∗⎤⎦⎥⎥⎥⎥⎥⎥⎥→⎡⎣⎢⎢⎢⎢⎢⎢⎢∗∗∗∗∗∗∗∗⋮∗………⋱…∗∗∗⋮∗⎤⎦⎥⎥⎥⎥⎥⎥⎥⋯→⎡⎣⎢⎢⎢⎢⎢⎢⎢∗∗∗∗∗∗∗∗⋱………⋱∗∗∗∗⋮∗⎤⎦⎥⎥⎥⎥⎥⎥⎥.
    The QR factorization of a upper-Hessenberg matrix is preserved by the QR algorithm and can be computed in O(n2)
    (see class lecture notes). Here, is an implementation of the Hessenberg reduction algorithm:
    function HessenbergReduction( A::Matrix )
        # Reduce A to a Hessenberg matrix H so that A and H are similar:
        
        n = size(A, 1)
        H = A
        if ( n > 2 )
            a1 = A[2:n, 1]
            e1 = zeros(n-1); e1[1] = 1
            sgn = sign(a1[1])
            v = (a1 + sgn*norm(a1)*e1); v = v./norm(v)
            Q1 = eye(n-1) - 2*(v*v')
            A[2:n,1] = Q1*A[2:n,1]
            A[1,2:n] = Q1*A[1,2:n]
            A[2:n,2:n] = Q1*A[2:n,2:n]*Q1' 
            H = HessenbergReduction( A[2:n,2:n] )
        else
            H = copy(A)
        end
       return A
    end
    
    HessenbergReduction (generic function with 1 method)
    Here, we check that the Hessenberg reduction works.
    A = rand(4,4)
    e = eigvals(A)
    H = HessenbergReduction( A )
    e ≈ eigvals(A)
    
    true
    After this our faster QR algorithm with look like this:
    Set A0=QTHAQH= upper-Hessenberg,for k = 1,2,... (until convergence)Compute Ak−1=QkRkSet Ak=RkQkend

    QR algorithm with shifts

    The unshift QR algorithm with Hessenberg reduction only costs O(n2)
    operations per iteration, but the convergence can be painfully slow. It typically requires thousands of iterations! This is too much. We need to do better.

    Deflation

    Notice that if Ak
    --- which is converging to upper-triangular --- had the form (notice the bold zero)
    ⎡⎣⎢⎢⎢⎢⎢⎢⎢∗∗∗∗∗∗∗∗⋱………⋱0∗∗∗⋮∗⎤⎦⎥⎥⎥⎥⎥⎥⎥=[B110Tuann],
    then ann is an eigenvalue of Ak and hence, also A (since Ak and A are similar). Moreover, the n−1 eigenvalues of B11 are the remaining n−1 eigenvalues of A.
    Thus, if we happen to be lucky enough for the Ak[n,n−1]
    entry to become close to zero, then we have approximately found one of the eigenvalues and can work with the (n−1)×(n−1) principle minor of Ak. This process is known as deflation.

    The shifted QR algorithm

    Instead of waiting for luck to allow for a deflation, Francis used a shifted version of the QR algorithm that is motivated by its origins from the power method. The shifted QR algorithm looks like this:
    Set A0=QTHAQH= upper-Hessenberg,for k = 1,2,... (until convergence)Compute a shift μkCompute Ak−1−μkI=QkRkSet Ak=RkQk+μkIend
    One can still check that this algorithm preserves the upper-Hessenberg structure and produces a sequence of similar matrices. The idea of the shift is to quickly make Ak[n,n−1]
    converge to zero. A reasonable choice of the shift is the Rayleigh quotient, where μk=Ak−1[n,n], because we would like μk to be an estimate for eigenvalue of A.
    The problem with the Rayleigh quotient shift is: it does not work. Consider, for example,
    [0110].
    Instead, Wilkinson designed a shift that does work on symmetric matrices. It looks at the 2×2
    submatrix Ak[n−1:n,n−1:n] and finds an estimate for an eigenvalue. If the 2×2 submatrix is [abbc], then Wilkinson's shift is given by
    μk=c−sign(δ)b2|δ|+δ2+b2−−−−−−√
    where δ=(a−c)/2. If δ=0, then sign(δ) can be arbitrarily selected as +1 or −1
    .
    function WilkinsonShift( a::Number, b::Number, c::Number )
        # Calculate Wilkinson's shift for symmetric matrices: 
        δ = (a-c)/2
        return c - sign(δ)*b^2/(abs(δ) + sqrt(δ^2+b^2))
    end
    
    function QRwithShifts( A::Matrix )
       # The QR algorithm for symmetric A with Rayleigh shifts and Hessenberg reduction. Please use eigvals() in 
       # Julia for serious applications.
        n = size(A,1)
        myeigs = zeros(n)
        if ( n == 1 )
            myeigs[1] = A[1,1]
        else
            I = eye( n )
            # Reduction to Hessenberg form:
            A = HessenbergReduction( A )
            # Let's start the shifted QR algorithm with 
            while( norm(A[n,n-1]) > 1e-10 )
    
                mu = WilkinsonShift( A[n-1,n-1], A[n,n], A[n-1,n] )
                # This line should use faster Hessenberg reduction:
                (Q,R) = qr(A - mu*I)
                # This line needs speeding up, currently O(n^3) operations!: 
                A = R*Q + mu*I
            end
            # Deflation and recurse:
            myeigs = [A[n,n] ; QRwithShifts( A[1:n-1, 1:n-1] )]
        end
        return myeigs
    end
    
    QRwithShifts (generic function with 1 method)
    For symmetric matrices, Wilkinson shifts and the shifted QR algorithm will always converge (in exact arithmetic). For example,
    n = 100
    A = randn(n,n); A = A'*A
    er = QRwithShifts(A)
    sort(er) ≈ sort(eigvals(A))
    
    true

    The QR algorithm on nonsymmetric matrices

    Despite there being no general convergence proof for shifted versions of the QR algorithm on nonsymmetric matrices, there is not a single example I know (at the time of writing) for which the current QR algorithm does not converge. It is extremely robust nowadays and should be used with confidence.

    The man behind the QR algorithm

    John Francis is an English computer scientist, who invented the QR algorithm in 1961. A year later he left the field of numerical analysis and had no idea of the impact of his work. In 2007, Gene Golub and Frank Uhlig managed to contacted him. He was the opening speaker at a mini-symposium that marked 50 years of the QR algorithm, held at the 23rd Biennial Conference on Numerical Analysis in Glasgow in June 2009.
    alt text
  • Remove the assumption that A
  • miércoles, 4 de octubre de 2017

    Raices de polinomios - Metodo de Bairstow

    https://adrian0294.wordpress.com/tag/metodo-de-bairstow/

    Metodo de Bairstow   Leave a comment

    Explicación del Método

    En análisis numérico, el método de Bairstow es un algoritmo eficiente de búsqueda de las raíces de un polinomio real de grado arbitrario.El algoritmo apareció por primera vez en el apéndice del libro “Aerodinámica Aplicada”, escrito por Leonard Bairstow y publicado en1920. El algoritmo se diferencia de otros métodos en que encuentra tanto las raíces reales como las imaginarias (en parejas complejas conjugadas), utilizando únicamente aritmética real.
    El método de BAIRSTOW, Es un método iterativo relacionado con los métodos de Müller y Newton Raphson. El método consiste en el cálculo de las raíces de un polinomio buscando factores cuadráticos x^2-rx-s del mismo, es decir, tales que:
    1
    Evidentemente, si x^2-rx-s no es un factor cuadrático de p(x) se tendrá:
    1
    Tomando el polinomio en orden descendente y los coeficientes del mismo en orden ascendente:
    Si en términos generales se tiene un polinomio descrito de la forma:
    1
    Y para efectos del ejemplo se tiene:
    1
    Si se asume como valor inicial para r=1 y s=1, se tiene que el polinomio factor cuadrático será:
    1
    Si se divide entre pc dará como resultado p1(x) y residuo Ax+B.
    De manera general se puede bosquejar así:
    1
    Donde Ax+B es el residuo de la división. Siendo A y B funciones de r y de s, de forma que el método consiste en encontrar los valores de r y s que hacen:
    1
    Para ello se aplica el método de newton Raphson en la forma conocida, lo que conlleva la evaluación de la matriz jacobiana del sistema anterior, así como de las funciones A y B, en cada iteración. Un modo de realizar estas evaluaciones, ya que la forma explícita de las funciones A(r,s) y B(r,s) no es conocida explícitamente, es construir el siguiente algoritmo:
    1
    Y encontrar los valores de A, B, A1 y B1 mediante el proceso similar al de Hörner siguiente que se obtiene al desarrollar los productos e identificar los coeficientes:
    Sean:
    1
    Resumiendo
    Dado un polinomio de n potencia se encuentran dos factores, un  polinomio cuadrático y un polinomio de grado n-2.
    La principal diferencia de este método, respecto a otros, es que permite calcular todas las raíces de un polinomio (reales e imaginarias).
    Recuerde la forma factorizada de un polinomio por ejemplo:
    1
    Si se divide entre un factor que no es una raíz (por ejemplo, x+6), el cociente podría ser un polinomio de cuarto orden. Sin embargo, en este caso, podría haber residuo. Con estas bases se puede elaborar un algoritmo para determinar la raíz de un polinomio:
    • Suponiendo que el valor inicial de la raíz es x = t;
    • Al dividir el polinomio entre el factor x – t,
    • Determinando si existe un residuo, si no el valor es perfecto y la raíz es igual a t.
    Si hay un residuo, el valor puede ser ajustado sistemáticamente y el procedimiento repetirse hasta que el residuo desaparezca y la raíz sea localizada.
    El método de Bairstow se basa por lo general en esta aproximación. El proceso matemático depende de dividir el polinomio entre un factor.
    Por ejemplo, Tomando el polinomio general con coeficientes iguales se tiene el polinomio general así:
    1
    Consecuentemente el proceso matemático depende de dividir el polinomio fn(x) entre un factor, tomando en cuenta la discusión del polinomio de deflación como sigue a continuación.
    Supóngase que se tiene la raíz de orden n-esimo, y teniendo un adecuado procedimiento para eliminar la raíz encontrada, a este procedimiento de eliminar la raíz se le llama deflación polinomial.
    Tomando el polinomio y coeficientes en Orden Ascendente de la forma general de un polinomio de orden n:
    1
    Se tiene un polinomio:
    1
    Ahora suponga que se divide la función polinomial de quinto orden por un factor de manera que se elimine una de sus raíces por ejemplo el factor (x+3) y se tiene una función de cuarto orden:
    1
    Con residuo cero para este caso.
    Así se tiene que la forma general de un polinomio entre un factor x-t dará un segundo polinomio de un orden más bajo:
    1
    con residuo R=b0 en donde los coeficientes son obtenidos por la relación de recurrencia:
    1
    Para permitir la evaluación de raíces complejas este método divide la función entre el factor cuadrático:
    1
    Aplicándolo en la ecuación 1
    Resultando: 1
    Con residuo: 1
    Y aplicando la relación de recurrencia se obtiene los siguientes coeficientes para la ecuación anterior:
    1
    Se introduce el factor cuadrático para la determinación de las raíces complejas, porque si los coeficientes del polinomio original son reales, las raíces complejas se presentan en pares conjugados.
    Si 1 es un divisor exacto del polinomio, las raíces complejas pueden ser determinadas con la formula cuadrática, por lo que el método cuadrático se reduce solo a determinar r y s que provocan que el factor cuadrático sea un divisor exacto y por consiguiente se obtiene un residuo igual a cero.
    Entonces si 1 deben ser cero. Esto para que los valores de inicio al evaluar r y s conduzcan a este resultado, se debe de aplicar un camino para los valores iniciales o de inicio de manera que b0 y b1 tiendan a cero para ello se utiliza una técnica similar a la de Newton-Raphson.
    Pues b0 como b1 son funciones de r y s y se expanden utilizando la serie de Taylor:
    1
    Los valores de la parte izquierda de la igualdad son evaluados en r y s. Observe que el segundo término y el término de orden superior se han despreciado. Ya que en forma implícita – r y – s son muy pequeños y los términos de orden superior pueden ser despreciados, pero otra consideraciones que los valores de inicio de son tan cercanos a los valores de r y s de las raíces.
    Para dar un valor inicial que se acerque a las raíces es el colocar las ecuaciones anteriores igual a cero y que resulte:
    1
    Si las variables ∆r y ∆s forman un sistema de ecuaciones de dos incógnitas y el método de Bairstow muestra que las derivadas parciales pueden resolverse por división sintética de las b en forma similar al camino en que las b en sí mismas fueron derivadas:
    1
    Entonces las derivadas parciales se obtienen por división sintética de las b, y las b con las derivadas parciales son sustituidas en las ecuaciones:
    1
    Y se obtiene:
    1
    Estas ecuaciones pueden ser resueltas para mejorar los valores de r y s, se podría utilizar el error aproximado para cada paso pero no es para nuestro caso realmente utilizado pero quedaría de la siguiente forma:
    1
    Cuando los dos valores fallan bajo un criterio especificado las raíces pueden determinarse con la siguiente ecuación:
    1
    Aquí pueden caber tres posibilidades:
    1. El cociente es un polinomio de tercer orden o mayor. Para este caso, el método de Bairstow podría aplicarse al cociente para evaluar un nuevo valor de r y s. Los valores anteriores de r y s pueden servir como valores iniciales de para esta aplicación.
    2. El cociente es cuadrático. Para este caso, el residuo de las raíces puede evaluarse con la ecuación: 1
    3. El cociente es un polinomio de primer orden. Para este caso, el residuo es una sola raíz que puede evaluarse simplemente como: x=-s/r



    Algoritmo

    1

    Diagrama de Flujo

     Diagrama de Flujo Bairstow

     Resultados

    • Comence ingresando los coeficientes de la funcion en orden decendente, esto quiere decir que primero se coloca el coeficiente que acompaña a la variable de mayor grado, y apartir de ahi desciende hasta llegar al termino que no acompaña variable.
    • Se ingresan los valores iniciales de r0 y so, asi como el error bajo el cual se quiere trabajar.
    • Damos aceptar
    • Y a continuacion el programa arroja unos valores de x1=.05 y x2=-1
    1 (2)
    • x1=.05 y x2=-1 son dos raices reales del polinomio original de quinto grado f5(x)=x^5-3.5*x^4+2.75*x^3+2.125*x^2-3.875*x+1.25

    Referencias