-
Notifications
You must be signed in to change notification settings - Fork 3
/
Complex.c
65 lines (55 loc) · 1012 Bytes
/
Complex.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <math.h>
#include "Complex.h"
complex cplus(complex a, complex b) {
a.x += b.x;
a.y += b.y;
return(a);
}
complex cmltp(complex a, complex b) {
complex c;
c.x = a.x*b.x - a.y*b.y;
c.y = a.x*b.y + a.y*b.x;
return(c);
}
complex cngtv(complex a) {
a.x = -a.x;
a.y = -a.y;
return(a);
}
complex cinvs(complex a) {
complex dmltp(float, complex);
complex conjg(complex a);
return(dmltp(1./(a.x*a.x+a.y*a.y), conjg(a)));
}
complex conjg(complex a) {
a.y = -a.y;
return(a);
}
complex dmltp(float a, complex b) {
b.x *= a;
b.y *= a;
return(b);
}
complex csqrt(complex a) {
double mo, ar;
double ccabs(complex);
mo = sqrt(ccabs(a));
ar = 0.5*atan2(a.y, a.x);
a.x = mo*cos(ar);
a.y = mo*sin(ar);
return(a);
}
complex cmplx(float x, float y) {
complex a;
a.x = x;
a.y = y;
return(a);
}
complex cphase(complex w) {
double mo;
mo = exp(w.x);
return cmplx(mo*cos(w.y), mo*sin(w.y));
}
double ccabs(complex a) {
return(sqrt(a.x*a.x+a.y*a.y));
}