rank_one_update Programmers Guide Contents | Index |  Search

Category:algorithms Component type:function
Prototype
template <class Matrix, class VecX, class VecY>
void rank_one_update(Matrix A, const VecX& x, const VecY& y) ;
Description
Also known as the outer product of two vectors.
```       y = [ 1  2  3 ]

[ 1 ] [ 1  2  3 ]
x = [ 2 ] [ 2  4  6 ] => A
[ 3 ] [ 3  6  9 ]
[ 4 ] [ 4  8 12 ]
```

When using this algorithm with a symmetric matrix, x and y must be the same vector, or at least have the same values. Otherwise the resulting matrix is not symmetric.

Definition
mtl.h
Requirements on types
• Matrix::value_type, VecX::value_type, and VecY::value_type must be the same type
• the multiplication operator must be defined for Matrix::value_type
• the addition operator must be defined for Matrix::value_type
Preconditions
• A.nrows() <= x.size()
• A.ncols() <= y.size()
• A has rectangle shape and is dense
Complexity
Example
In rank_one.cc:
```  typedef matrix< double,
rectangle<>,
dense<>,
column_major >::type Matrix;
typedef Matrix::size_type sizeT;
const sizeT M = 4, N = 3;
Matrix A(M, N);
dense1D<double> x(M), y(N);
double alpha = 1.0;
// fill A, x, and y ...
rank_one_update(A, scaled(x, alpha), y);

```
Notes