forked from robin1001/beamforming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix-test.cc
147 lines (128 loc) · 3.03 KB
/
matrix-test.cc
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
/* Created on 2016-08-30
* Author: Zhang Binbin
*/
#include <stdio.h>
#include "matrix.h"
void TestMatrixAdd() {
Matrix mat1, mat2;
int r, c;
float tmp;
scanf("%d%d", &r, &c);
mat1.Resize(r, c);
mat2.Resize(r, c);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%f", &tmp);
mat1(i, j) = tmp;
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%f", &tmp);
mat2(i, j) = tmp;
}
}
mat1.Add(mat2);
mat1.Print();
}
void TestMatrixMul() {
Matrix mat1, mat2;
int r1, c1;
scanf("%d%d", &r1, &c1);
mat1.Resize(r1, c1);
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c1; j++) {
scanf("%f", &mat1(i, j));
}
}
int r2, c2;
scanf("%d%d", &r2, &c2);
mat2.Resize(r2, c2);
for (int i = 0; i < r2; i++) {
for (int j = 0; j < c2; j++) {
scanf("%f", &mat2(i, j));
}
}
Matrix mat3;
mat3.Mul(mat1, mat2);
mat3.Print();
}
void TestMatrixInverse() {
Matrix mat1, mat2;
int r1, c1;
scanf("%d%d", &r1, &c1);
mat1.Resize(r1, c1);
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c1; j++) {
scanf("%f", &mat1(i, j));
}
}
mat2.Inverse(mat1);
mat2.Print();
}
void TestComplexMatrixAdd() {
ComplexMatrix mat1, mat2;
int r1, c1;
scanf("%d%d", &r1, &c1);
mat1.Resize(r1, c1);
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c1; j++) {
scanf("%f + %fi", &mat1(i, j).real, &mat1(i, j).img);
}
}
//mat1.Print();
mat2.Resize(r1, c1);
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c1; j++) {
scanf("%f + %fi", &mat2(i, j).real, &mat2(i, j).img);
}
}
//mat2.Print();
mat1.Add(mat2);
mat1.Print();
}
void TestComplexMatrixMul() {
ComplexMatrix mat1, mat2;
int r1, c1;
scanf("%d%d", &r1, &c1);
mat1.Resize(r1, c1);
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c1; j++) {
scanf("%f + %fi", &mat1(i, j).real, &mat1(i, j).img);
}
}
int r2, c2;
scanf("%d%d", &r2, &c2);
mat2.Resize(r2, c2);
for (int i = 0; i < r2; i++) {
for (int j = 0; j < c2; j++) {
scanf("%f + %fi", &mat2(i, j).real, &mat2(i, j).img);
}
}
ComplexMatrix mat3;
mat3.Mul(mat1, mat2);
mat3.Print();
}
void TestComplexMatrixInverse() {
ComplexMatrix mat1, mat2;
int r1, c1;
scanf("%d%d", &r1, &c1);
mat1.Resize(r1, c1);
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c1; j++) {
scanf("%f + %fi", &mat1(i, j).real, &mat1(i, j).img);
}
}
//mat1.Print();
mat2.Inverse(mat1);
mat2.Print();
}
int main() {
//TestMatrixAdd();
//TestMatrixMul();
TestMatrixInverse();
//TestComplexMatrixAdd();
//TestComplexMatrixMul();
//TestComplexMatrixInverse();
return 0;
}