9#ifndef HDNUM_QRHOUSHOLDER_HH
10#define HDNUM_QRHOUSHOLDER_HH
19#include "densematrix.hh"
26DenseMatrix<REAL> creat_I_matrix(
size_t n) {
27 DenseMatrix<REAL> res(n, n, 0);
28 for (
size_t i = 0; i < n; i++) {
36template <
typename REAL>
53 for (
size_t j = 0;
j < n;
j++) {
55 for (
size_t i =
j;
i <
m;
i++) {
56 s = s + pow(A(
i,
j), 2);
59 v[
j] = (-1.0) *
sgn(A(
j,
j)) * s;
60 REAL fak = sqrt(s * (s + std::abs(A(
j,
j))));
62 for (
size_t k =
j;
k <
m;
k++) {
65 for (
size_t i =
j + 1;
i < n;
i++) {
67 for (
size_t k =
j;
k <
m;
k++) {
68 s = s + (A(
k,
j) * A(
k,
i));
70 for (
size_t k =
j;
k <
m;
k++) {
71 A(
k,
i) = A(
k,
i) - (A(
k,
j) * s);
75 for (
size_t i =
m;
i >= 0;
i--) {
102 for (
size_t j = 0;
j < n;
j++) {
104 for (
size_t i =
j;
i <
m;
i++) {
105 s = s + pow(A(
i,
j), 2);
108 v[
j] = (-1.0) *
sgn(A(
j,
j)) * s;
109 REAL fak = sqrt(s * (s + std::abs(A(
j,
j))));
111 for (
size_t k =
j;
k <
m;
k++) {
114 for (
size_t i =
j + 1;
i < n;
i++) {
116 for (
size_t k =
j;
k <
m;
k++) {
117 s = s + (A(
k,
j) * A(
k,
i));
119 for (
size_t k =
j;
k <
m;
k++) {
120 A(
k,
i) = A(
k,
i) - (A(
k,
j) * s);
124 for (
size_t i =
m;
i >= 0;
i--) {
133 for (
size_t j = 0;
j < n;
j++) {
138 for (
size_t i = 0;
i <
m;
i++) {
159 std::cout <<
"H[" <<
j + 1 <<
"]" <<
TempQ;
170 for (
size_t j = 0;
j <
m;
j++) {
175 for (
size_t i = 0;
i <
m;
i++) {
196 std::cout <<
"H[" <<
j + 1 <<
"]" <<
TempQ;
Class with mathematical matrix operations.
Definition densematrix.hh:33
size_t rowsize() const
get number of rows of the matrix
Definition densematrix.hh:136
size_t colsize() const
get number of columns of the matrix
Definition densematrix.hh:153
DenseMatrix transpose() const
Transposition.
Definition densematrix.hh:350
size_t sgn(REAL val)
Function that return the sign of a number.
Definition qrhousholder.hh:37
DenseMatrix< REAL > qrhousholderexplizitQ(DenseMatrix< REAL > &A, hdnum::Vector< REAL > &v, bool show_Hi=false)
Funktion that calculate the QR decoposition in place and return Q the elements of A will be replaced ...
Definition qrhousholder.hh:94
void qrhousholder(DenseMatrix< REAL > &A, hdnum::Vector< REAL > &v)
Funktion that calculate the QR decoposition in place the elements of A will be replaced with the elem...
Definition qrhousholder.hh:50