Peano
Loading...
Searching...
No Matches
GramSchmidt.cpph
Go to the documentation of this file.
1template<int Rows, int Cols, typename Scalar>
6) {
7 for (int i=0; i < Rows; i++){
8 Q(i,0) = A(i,0);
9 }
10
11 for (int k=0; k < Cols; k++){
12 // Compute norm of k-th column vector of (modified) A
13 R(k,k) = 0.0;
14 for (int i=0; i < Rows; i++){
15 R(k,k) += std::pow(A(i,k), 2);
16 }
17 R(k,k) = std::sqrt(R(k,k));
18
19 // Normalize k-th column of matrix Q
20 for (int i=0; i < Rows; i++){
21 Q(i,k) = A(i,k) / R(k,k);
22 }
23
24 // Compute entries in R and next orthonormal vector
25 for (int j=k+1; j < Cols; j++){
26 // Compute entries of R from current Q and A
27 for (int i=0; i < Rows; i++){
28 R(k,j) += Q(i,k) * A(i,j);
29 }
30 // Subtract contributions from computed to open orthonormal vectors
31 for (int i=0; i < Rows; i++){
32 A(i,j) -= Q(i,k) * R(k,j);
33 }
34 }
35 }
36}
37
Static (i.e.
Definition Matrix.h:42
void modifiedGramSchmidt(Matrix< Rows, Cols, Scalar > A, Matrix< Rows, Cols, Scalar > &Q, Matrix< Cols, Cols, Scalar > &R)
Produces an economy-size QR decomposition of a matrix A, A is changed.