RcdMathLib_doc
Open Source Library for Linear and Non-linear Algebra
householder_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
3  * 2020 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser General
6  * Public License v2.1. See the file LICENSE in the top level directory for more
7  * details.
8  */
9 
24 #include <stdbool.h>
25 #include <stdio.h>
26 
27 #include "matrix.h"
28 #include "qr_householder.h"
29 
30 
31 void householder_test(void)
32 {
33  puts("############ Test the Householder algorithm ###############");
34  matrix_t A[10][5] = { { 0.8147, 0.1576, 0.6557, 0.7060, 0.4387 },
35  { 0.9058, 0.9706, 0.0357, 0.0318, 0.3816 },
36  { 0.1270, 0.9572, 0.8491, 0.2769, 0.7655 },
37  { 0.9134, 0.4854, 0.9340, 0.0462, 0.7952 },
38  { 0.6324, 0.8003, 0.6787, 0.0971, 0.1869 },
39  { 0.0975, 0.1419, 0.7577, 0.8235, 0.4898 },
40  { 0.2785, 0.4218, 0.7431, 0.6948, 0.4456 },
41  { 0.5469, 0.9157, 0.3922, 0.3171, 0.6463 },
42  { 0.9575, 0.7922, 0.6555, 0.9502, 0.7094 },
43  { 0.9649, 0.9595, 0.1712, 0.0344, 0.7547 } };
44  uint8_t m = 10, n = 5;
45  matrix_t copy_A[m][n];
46  matrix_t Q_red[m][n];
47  matrix_t Q[m][m];
48 
49  matrix_copy(m, n, A, copy_A);
50  matrix_clear(m, n, Q_red);
51  qr_householder_decomp(m, n, copy_A, n, Q_red, true);
52  printf("Q_red = ");
53  matrix_flex_print(m, n, Q_red, 7, 4);
54  printf("R_red = ");
55  matrix_flex_print(n, n, copy_A, 7, 4);
56 
57  matrix_copy(m, n, A, copy_A);
58  matrix_clear(m, m, Q);
59  qr_householder_decomp(m, n, copy_A, m, Q, false);
60  printf("Q = ");
61  matrix_flex_print(m, m, Q, 7, 4);
62  printf("R = ");
63  matrix_flex_print(m, n, copy_A, 7, 4);
64 
65  matrix_t B[4][4] = {
66  { 6, 0, 0, 6 },
67  { 2, 5, 0, 4 },
68  { 0, 6, 2, 3 },
69  { 0, 1, 5, 5 }
70  };
71  m = 4;
72  n = 4;
73  matrix_t Q1_red[m][n];
74  qr_householder_decomp(m, n, B, m, Q1_red, true);
75  printf("Q1 = ");
76  matrix_flex_print(m, m, Q1_red, 7, 4);
77  printf("R1 = ");
78  matrix_flex_print(m, n, B, 7, 4);
79 }
qr_householder_decomp
int8_t qr_householder_decomp(uint8_t m, uint8_t n, matrix_t A[][n], uint8_t q_col_num, matrix_t Q[][q_col_num], bool reduced)
Computes the QR decomposition of the matrix A by using the Householder algorithm.
Definition: qr_householder.c:33
matrix_clear
void matrix_clear(uint8_t m, uint8_t n, matrix_t matrix[m][n])
Clear all the elements of the vector.
Definition: matrix.c:46
qr_householder.h
Householder algorithm for the QR-decomposition.
matrix.h
Matrix computations.
matrix_flex_print
void matrix_flex_print(uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t before_dec, uint8_t after_dec)
Display the values of the matrix elements.
Definition: matrix.c:220
matrix_copy
void matrix_copy(uint8_t m, uint8_t n, matrix_t src_matrix[m][n], matrix_t dest_matrix[m][n])
Copy the elements of a matrix to another matrix.
Definition: matrix.c:83
matrix_t
#define matrix_t
Define the data type of the matrix elements.
Definition: matrix.h:38
householder_test
void householder_test(void)
Examples of the Householder algorithm.
Definition: householder_test.c:31