-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.c
49 lines (40 loc) · 1.15 KB
/
matrix.c
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
#include <stdio.h>
#include "matrix.h"
void mz(Matrix *Mptr) {
(*Mptr).z11.x = 0;
(*Mptr).z11.y = 0;
(*Mptr).z12.x = 0;
(*Mptr).z12.y = 0;
(*Mptr).z21.x = 0;
(*Mptr).z21.y = 0;
(*Mptr).z22.x = 0;
(*Mptr).z22.y = 0;
}
void mi(Matrix *Mptr) {
(*Mptr).z11.x = 1;
(*Mptr).z11.y = 0;
(*Mptr).z12.x = 0;
(*Mptr).z12.y = 0;
(*Mptr).z21.x = 0;
(*Mptr).z21.y = 0;
(*Mptr).z22.x = 1;
(*Mptr).z22.y = 0;
}
Matrix mm(Matrix M1, Matrix M2) {
Matrix M;
M.z11 = ca(cm(M1.z11, M2.z11), cm(M1.z12, M2.z21));
M.z12 = ca(cm(M1.z11, M2.z12), cm(M1.z12, M2.z22));
M.z21 = ca(cm(M1.z21, M2.z11), cm(M1.z22, M2.z21));
M.z22 = ca(cm(M1.z21, M2.z12), cm(M1.z22, M2.z22));
return M;
}
double md(Matrix M1, Matrix M2) {
Complex z11, z22;
z11 = ca(cm(cc(M1.z11), M2.z11), cm(cc(M1.z21), M2.z21));
z22 = ca(cm(cc(M1.z12), M2.z12), cm(cc(M1.z22), M2.z22));
return my_cabs(ca(z11, z22));
}
void pm(FILE *out, Matrix M) {
fprintf(out, "(%19.15e, %19.15e) (%19.15e, %19.15e)\n", M.z11.x, M.z11.y, M.z12.x, M.z12.y);
fprintf(out, "(%19.15e, %19.15e) (%19.15e, %19.15e)\n", M.z21.x, M.z21.y, M.z22.x, M.z22.y);
}