| 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 |
package dr.math; |
| 27 |
|
| 28 |
import dr.math.matrixAlgebra.Vector; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class ComplexArray { |
| 34 |
|
| 35 |
public final double[] real; |
| 36 |
public final double[] complex; |
| 37 |
public final int length; |
| 38 |
|
| 39 |
public ComplexArray(double[] real) { |
| 40 |
this(real, new double[real.length]); |
| 41 |
} |
| 42 |
|
| 43 |
public ComplexArray(double[] real, double[] complex) { |
| 44 |
this.real = real; |
| 45 |
this.complex = complex; |
| 46 |
this.length = real.length; |
| 47 |
} |
| 48 |
|
| 49 |
public void conjugate() { |
| 50 |
for (int i = 0; i < length; ++i) { |
| 51 |
complex[i] = -complex[i]; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
public ComplexArray product(ComplexArray x) { |
| 56 |
double[] newReal = new double[length]; |
| 57 |
double[] newComplex = new double[length]; |
| 58 |
for (int i = 0; i < length; ++i) { |
| 59 |
|
| 60 |
final double a = real[i]; |
| 61 |
final double b = complex[i]; |
| 62 |
final double c = x.real[i]; |
| 63 |
final double d = x.complex[i]; |
| 64 |
newReal[i] = a * c - b * d; |
| 65 |
newComplex[i] = a * d + b * c; |
| 66 |
} |
| 67 |
return new ComplexArray(newReal, newComplex); |
| 68 |
} |
| 69 |
|
| 70 |
public String toString() { |
| 71 |
return "\nReal : " + new Vector(real).toString() + |
| 72 |
"\nComplex: " + new Vector(complex).toString(); |
| 73 |
} |
| 74 |
|
| 75 |
public static double[] interleave(double[] real, double[] complex) { |
| 76 |
final int length = real.length; |
| 77 |
double[] out = new double[length * 2]; |
| 78 |
for (int i = 0; i < length; i++) { |
| 79 |
out[2 * i] = real[i]; |
| 80 |
out[2 * i + 1] = complex[i]; |
| 81 |
} |
| 82 |
return out; |
| 83 |
} |
| 84 |
} |