-
Notifications
You must be signed in to change notification settings - Fork 3
/
matrix_properties.h
166 lines (142 loc) · 3.93 KB
/
matrix_properties.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* @file
*/
/*
* Copyright (c) 2016 Andrei Parente
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
**/
#ifndef MATRIX_PROPERTIES_H
#define MATRIX_PROPERTIES_H
#include "matrix.h"
#include "cholesky.h"
#include "matrix_norms.h"
#include "vandermonde.h"
/**
* Confere se mat é tridiagonal.
* @author Andrei Parente
*/
static int tridiagonal_check(const matrix_t *mat)
{
size_t i;
for (i = 0; i < mat->rows; ++i) {
size_t j;
for (j = 0; j < mat->columns; ++j) {
if (i == j || i == j + 1 || j == i + 1) {
if (matrix_get_at(mat, i, j) == 0) {
return 0;
}
} else if (matrix_get_at(mat, i, j) != 0) {
return 0;
}
}
}
return 1;
}
/**
* Confere se mat é ortogonal.
* @author Andrei Parente
*/
static int orthogonal_check(const matrix_t *mat)
{
matrix_t *id = matrix_new(mat->rows, mat->columns);
id = matrix_load_identity(id);
matrix_t *transposed = matrix_transpose(mat);
matrix_t *mulled = matrix_mul_matrix(mat, transposed);
int result = matrix_cmp(id, mulled);
matrix_free(transposed);
matrix_free(mulled);
if (result == 1) {
return 1;
}
return 0;
}
/**
* Confere se mat é simétrica.
* @author Andrei Parente
*/
static int symmetric_check(const matrix_t *mat)
{
matrix_t *transposed = matrix_transpose(mat);
int result = matrix_cmp(mat, transposed);
matrix_free(transposed);
return result;
}
/**
* Confere se mat é positiva definida.
* @author Andrei Parente
*/
static int positive_definite_check(const matrix_t *mat)
{
matrix_t *factor = cholesky_factor(mat);
if (factor == NULL) {
return 0;
}
matrix_free(factor);
return 1;
}
/**
* Verifica se a matriz é estritamente diagonal dominante
* @autor Pedro da Luz
*/
static int strictly_dominant_diagonal_check(const matrix_t *A)
{
matrix_t* singleRow;
singleRow = matrix_new(1, A->columns);
size_t i, j;
for(i = 0; i < A->rows; i++)
{
for(j = 0; j < A->columns; j++)
matrix_set_at(singleRow, 0, j, matrix_get_at(A, i, j));
double norm = vector_norm1(singleRow);
for(j = 0; j < A->columns; j++)
{
if(fabs(matrix_get_at(A, i, j)) < norm)
return 0;
}
}
matrix_free(singleRow);
return 1;
}
/**
* Verifica se os vetores da matriz são lineramente independentes
* Pelo método da determinante em matrizes de ordem NxN
*
* @param A, matriz composta por vetores linha
*
* @author Pedro da Luz
*/
static int vector_lineary_independence_det_check(const matrix_t* A)
{
if(vandermonde_check(A) == 1)
{
if(vandermonde_determinant(A) != 0)
return 1;
else
return 0;
}
else
{
if(matrix_get_determinant(A) != 0)
return 1;
else
return 0;
}
}
#endif