RcdMathLib_doc
Open Source Library for Linear and Non-linear Algebra
qr_pinv_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 <qr_pseudo_inverse.h>
25 #include <stdio.h>
26 
27 #include "matrix.h"
28 #include "qr_common.h"
29 
30 void qr_pinv_test(void)
31 {
32  puts("\n\n++++++++++++++++++++++++++++++ QR Pseudo-Inverse ++++++++++++++++++++++++++++++\n");
33  puts("************ Householder: MATRIX A ************");
34  matrix_t A[10][5] = {
35  { 0.8147, 0.1576, 0.6557, 0.7060, 0.4387 },
36  { 0.9058, 0.9706, 0.0357, 0.0318, 0.3816 },
37  { 0.1270, 0.9572, 0.8491, 0.2769, 0.7655 },
38  { 0.9134, 0.4854, 0.9340, 0.0462, 0.7952 },
39  { 0.6324, 0.8003, 0.6787, 0.0971, 0.1869 },
40  { 0.0975, 0.1419, 0.7577, 0.8235, 0.4898 },
41  { 0.2785, 0.4218, 0.7431, 0.6948, 0.4456 },
42  { 0.5469, 0.9157, 0.3922, 0.3171, 0.6463 },
43  { 0.9575, 0.7922, 0.6555, 0.9502, 0.7094 },
44  { 0.9649, 0.9595, 0.1712, 0.0344, 0.7547 }
45  };
46 
47  uint8_t m, n;
48  m = 10;
49  n = 5;
50  matrix_t pinv_A[n][m];
51 
52  qr_get_pinv(m, n, A, pinv_A, QR_Householder);
53 
54  printf("pinv_A = ");
55  matrix_flex_print(n, m, pinv_A, 8, 4);
56  puts("");
57 
58  puts("************ Householder: MATRIX B ************");
59  matrix_t B[7][7] =
60  {
61  { 0.8147, 0.5469, 0.8003, 0.0357, 0.6555, 0.8235, 0.7655 },
62  { 0.9058, 0.9575, 0.1419, 0.8491, 0.1712, 0.6948, 0.7952 },
63  { 0.1270, 0.9649, 0.4218, 0.9340, 0.7060, 0.3171, 0.1869 },
64  { 0.9134, 0.1576, 0.9157, 0.6787, 0.0318, 0.9502, 0.4898 },
65  { 0.6324, 0.9706, 0.7922, 0.7577, 0.2769, 0.0344, 0.4456 },
66  { 0.0975, 0.9572, 0.9595, 0.7431, 0.0462, 0.4387, 0.6463 },
67  { 0.2785, 0.4854, 0.6557, 0.3922, 0.0971, 0.3816, 0.7094 }
68  };
69 
70  m = 7;
71  n = 7;
72  matrix_t pinv_B[m][n];
73 
74  qr_get_pinv(m, n, B, pinv_B, QR_Householder);
75 
76  printf("pinv_B = ");
77  matrix_flex_print(n, m, pinv_B, 8, 4);
78  puts("");
79 
80  puts("************ Givens: MATRIX A ************");
81 
82  m = 10;
83  n = 5;
84 
85  qr_get_pinv(m, n, A, pinv_A, QR_Givens);
86 
87  printf("pinv_A = ");
88  matrix_flex_print(n, m, pinv_A, 8, 4);
89  puts("");
90 
91  puts("************ Givens: MATRIX B ************");
92 
93  m = 7;
94  n = 7;
95 
96  qr_get_pinv(m, n, B, pinv_B, QR_Givens);
97 
98  printf("pinv_B = ");
99  matrix_flex_print(n, m, pinv_B, 8, 4);
100  puts("");
101 
102 }
qr_pseudo_inverse.h
QR decomposition algorithms to compute the pseudo-inverse of a matrix.
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
qr_get_pinv
int8_t qr_get_pinv(uint8_t m, uint8_t n, matrix_t A[m][n], matrix_t pinv_A[n][m], enum QR_ALGORITHM algo)
Calculate the pseudo inverse of a rectangular matrix using the QR decomposition.
Definition: qr_pseudo_inverse.c:32
qr_common.h
Common definitions and implementations for the QR-decomposition. Provide necessary methods to constru...
matrix_t
#define matrix_t
Define the data type of the matrix elements.
Definition: matrix.h:38
qr_pinv_test
void qr_pinv_test(void)
Examples of the QR-based pseudo-inverse algorithm.
Definition: qr_pinv_test.c:30