9#ifndef NUMERICAL_METHODS_QR_DECOMPOSE_H_
10#define NUMERICAL_METHODS_QR_DECOMPOSE_H_
36 const char separator =
' ';
39 for (
size_t row = 0; row < v.size(); row++) {
40 for (
size_t col = 0; col < v[row].size(); col++)
55 const char separator =
' ';
58 for (
size_t row = 0; row < v.size(); row++) {
111 std::cerr <<
"[" << __func__ <<
"] Possible division by zero\n";
115 double scalar = num / deno;
157 for (
int i = 0; i < COLUMNS; i++) {
167 for (j = 0; j < ROWS; j++) {
168 tmp_vector[j] = A[j][i];
169 col_vector[j] = A[j][i];
171 for (j = 0; j < i; j++) {
172 for (
int k = 0; k < ROWS; k++) {
173 col_vector2[k] = Q[0][k][j];
175 col_vector2 =
vector_proj(col_vector, col_vector2);
176 tmp_vector -= col_vector2;
185 for (j = 0; j < ROWS; j++) Q[0][j][i] = tmp_vector[j] / mag;
192 for (
int kk = 0; kk < ROWS; kk++) {
193 col_vector[kk] = Q[0][kk][i];
200 for (
int k = i; k < COLUMNS; k++) {
201 for (
int kk = 0; kk < ROWS; kk++) {
202 col_vector2[kk] = A[kk][k];
204 R[0][i][k] = (col_vector * col_vector2).sum();
Functions to compute QR decomposition of any rectangular matrix.
std::valarray< T > vector_proj(const std::valarray< T > &a, const std::valarray< T > &b)
Definition qr_decompose.h:104
void qr_decompose(const std::valarray< std::valarray< T > > &A, std::valarray< std::valarray< T > > *Q, std::valarray< std::valarray< T > > *R)
Definition qr_decompose.h:146
double vector_dot(const std::valarray< T > &a, const std::valarray< T > &b)
Definition qr_decompose.h:76
double vector_mag(const std::valarray< T > &a)
Definition qr_decompose.h:92
std::ostream & operator<<(std::ostream &out, std::valarray< std::valarray< T > > const &v)
Definition qr_decompose.h:33