Logo MTL4
Rank-One and Rank-Two Update

The application of rank-one and rank-two updates are illustrated in the following (hopefully self-explanatory) program:

#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

int main(int, char**)
{
    using namespace mtl;
    typedef std::complex<double>  cdouble;
    
    const unsigned n= 8;
    dense2D<cdouble>              A(n, n);

    A= 3.0;

    dense_vector<cdouble>         v(n), w(n);
    for (unsigned i= 0; i < size(v); i++)
        v[i]= cdouble(i+1, n-i), w[i]= cdouble(i+n);

    rank_one_update(A, v, w);
    std::cout << "A after rank-one update is \n" 
              << with_format(A, 9, 3) << "\n";

    A= 3.0;
    rank_two_update(A, v, w);
    std::cout << "A after rank-two update is \n"
              << with_format(A, 9, 3) << "\n";

    return 0;
}

The output of the matrix is formatted for better readability. The functions also work for sparse matrices although we cannot recommend this for the sake of efficiency.

In the future, updates will be also expressible with operators. For instance, rank_one_update(A, v, w) can be written as A+= conj(v) * trans(w) if v and w are column vectors (if w is a row vector the transposition can-and must-be removed). Thus, the orientation is relevant in operator notation where the functions rank_one_update and rank_two_update ignore the orientation.

Return to Banded Matrix View, Upper and Lower Triangular Views                                Table of Content                                Proceed to Other Matrix Functions


Rank-One and Rank-Two Update -- MTL 4 -- Peter Gottschling and Andrew Lumsdaine -- Gen. with rev. 7542 on Sat Aug 11 2012 by doxygen 1.7.6.1 -- © 2010 by SimuNova UG.