-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlasso_complex.cpp
62 lines (52 loc) · 1.12 KB
/
lasso_complex.cpp
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
#include <math.h>
#include "lasso_complex.h"
complex operator+(complex a, complex b){
complex c;
c.real = a.real+b.real;
c.imag = a.imag+b.imag;
return c;
}
complex operator-(complex a, complex b){
complex c;
c.real = a.real-b.real;
c.imag = a.imag-b.imag;
return c;
}
complex operator*(complex a, complex b){
complex c;
float r, i;
r = a.real*b.real-a.imag*b.imag;
i = a.imag*b.real+a.real*b.imag;
c.real = r;
c.imag = i;
return c;
}
complex operator/(complex a, complex b){
complex c;
float r, i, d;
r = a.real*b.real+a.imag*b.imag;
i = a.real*b.imag-a.imag*b.real;
d = a.real*a.real+b.real*b.real;
c.real = r/d;
c.imag = i/d;
return c;
}
complex cexp(complex a){
complex c;
float t = exp(a.real);
c.real = t*cos(a.imag);
c.imag = t*sin(a.imag);
return c;
}
float cabs(complex a){
return sqrt(a.real*a.real+a.imag*a.imag);
}
complex cpow(complex a, float b){
complex c;
float s = cabs(a);
float t = pow(s, b);
float u = acos(a.real/s)*b;
c.real = t*cos(u);
c.imag = t*sin(u);
return c;
}