RcdMathLib_doc
Open Source Library for Linear and Non-linear Algebra
lu_decomp_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 <stdio.h>
25 
26 #include "matrix.h"
27 #include "lu_decomp.h"
28 
29 void lu_decomp_test(void)
30 {
31  puts("############ Test the LU decomposition algorithm ###############");
32  matrix_t A[5][5] = { { 0.8147, 0.1576, 0.6557, 0.7060, 0.4387 },
33  { 0.9058, 0.9706, 0.0357, 0.0318, 0.3816 },
34  { 0.1270, 0.9572, 0.8491, 0.2769, 0.7655 },
35  { 0.9134, 0.4854, 0.9340, 0.0462, 0.7952 },
36  { 0.6324, 0.8003, 0.6787, 0.0971, 0.1869 }, };
37  uint8_t n;
38 
39  n = 5;
40  matrix_t L[n][n];
41  matrix_t P[n][n];
42  lu_decomp(n, A, L, P);
43  printf("L = ");
44  matrix_flex_print(n, n, L, 7, 4);
45  printf("U = ");
46  matrix_flex_print(n, n, A, 7, 4);
47  printf("P = ");
48  matrix_flex_print(n, n, P, 7, 4);
49 
50  matrix_t B[11][11] = {
51  { 0.4387, 0.6797, 0.5060, 0.2435, 0.9172, 0.1299, 0.2630, 0.9961, 0.2599, 0.1450,
52  0.4173 },
53  { 0.3816, 0.6551, 0.6991, 0.9293, 0.2858, 0.5688, 0.6541, 0.0782, 0.8001, 0.8530,
54  0.0497 },
55  { 0.7655, 0.1626, 0.8909, 0.3500, 0.7572, 0.4694, 0.6892, 0.4427, 0.4314, 0.6221,
56  0.9027 },
57  { 0.7952, 0.1190, 0.9593, 0.1966, 0.7537, 0.0119, 0.7482, 0.1067, 0.9106, 0.3510,
58  0.9448 },
59  { 0.1869, 0.4984, 0.5472, 0.2511, 0.3804, 0.3371, 0.4505, 0.9619, 0.1818, 0.5132,
60  0.4909 },
61  { 0.4898, 0.9597, 0.1386, 0.6160, 0.5678, 0.1622, 0.0838, 0.0046, 0.2638, 0.4018,
62  0.4893 },
63  { 0.4456, 0.3404, 0.1493, 0.4733, 0.0759, 0.7943, 0.2290, 0.7749, 0.1455, 0.0760,
64  0.3377 },
65  { 0.6463, 0.5853, 0.2575, 0.3517, 0.0540, 0.3112, 0.9133, 0.8173, 0.1361, 0.2399,
66  0.9001 },
67  { 0.7094, 0.2238, 0.8407, 0.8308, 0.5308, 0.5285, 0.1524, 0.8687, 0.8693, 0.1233,
68  0.3692 },
69  { 0.7547, 0.7513, 0.2543, 0.5853, 0.7792, 0.1656, 0.8258, 0.0844, 0.5797, 0.1839,
70  0.1112 },
71  { 0.2760, 0.2551, 0.8143, 0.5497, 0.9340, 0.6020, 0.5383, 0.3998, 0.5499, 0.2400,
72  0.7803 }
73  };
74 
75  n = 11;
76  matrix_t L1[n][n];
77  matrix_t P1[n][n];
78  lu_decomp(n, B, L1, P1);
79  printf("L1 = ");
80  matrix_flex_print(n, n, L1, 7, 4);
81  printf("U1 = ");
82  matrix_flex_print(n, n, B, 7, 4);
83  printf("P1 = ");
84  matrix_flex_print(n, n, P1, 7, 4);
85 }
lu_decomp.h
Computes the LU decomposition of the 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
lu_decomp_test
void lu_decomp_test(void)
Examples of the LU algorithm with pivoting.
Definition: lu_decomp_test.c:29
lu_decomp
uint8_t lu_decomp(uint8_t n, matrix_t A[][n], matrix_t L[][n], matrix_t P[][n])
Computes the LU decomposition of the matrix.
Definition: lu_decomp.c:31
matrix_t
#define matrix_t
Define the data type of the matrix elements.
Definition: matrix.h:38