/**************************************************************** * Forces Hermiticity by copying upper half of A to the lower one ****************************************************************/ public static bool forcehermitian(complex[,] a) { int i, j, n; complex v; if (rows(a) != cols(a)) { return(false); } n = rows(a); if (n == 0) { return(true); } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { v = a[j, i]; a[i, j].x = v.x; a[i, j].y = -v.y; } } return(true); }
public static void SetImage(Bitmap bmp, complex[,] img) { for (int i = 0; i < bmp.Height; i++) { for (int j = 0; j < bmp.Width; j++) { double pxl = img[j, i].Abs() * 500; bmp.SetPixel(i, j, Color.FromArgb((int)pxl, (int)pxl, (int)pxl)); } } }
public static void normalize(complex[,] v) { for (int i = 0; i < v.GetLength(1); i++) { double length = 0; for (int j = 0; j < v.GetLength(0); j++) { length += v[j, i].real * v[j, i].real; } length = Math.Sqrt(length); for (int j = 0; j < v.GetLength(0); j++) { v[j, i].real = v[j, i].real / length; } } }
/**************************************************************** * prints formatted matrix ****************************************************************/ public static string format(complex[,] a, int dps) { int i, j, m, n; n = cols(a); m = rows(a); complex[] line = new complex[n]; string[] result = new string[m]; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { line[j] = a[i, j]; } result[i] = format(line, dps); } return("{" + String.Join(",", result) + "}"); }
public static double[][,] getEigenFaces(complex[,] eigenVector, double[][,] difFace) { double[][,] eFaces = new double[eigenVector.GetLength(1)][, ]; for (int m = 0; m < eigenVector.GetLength(1); m++) { eFaces[m] = new double[difFace[0].GetLength(0), difFace[0].GetLength(1)]; for (int k = 0; k < eigenVector.GetLength(0); k++) { for (int i = 0; i < difFace[k].GetLength(0); i++) { for (int j = 0; j < difFace[k].GetLength(1); j++) { eFaces[m][i, j] += difFace[k][i, j] * eigenVector[m, k].real; } } } } return(eFaces); }
public cFFT(int N) { this.N = N; this.pi2 = 2 * 3.1415926f; log_2_N = (int)(Mathf.Log((float)N) / Math.Log(2.0)); reversed = new int[N]; // prep bit reversals for (int i = 0; i < N; i++) { reversed[i] = reverse(i); } int pow2 = 1; W = Arrays.InitializeWithDefaultInstances <ComplexW>(log_2_N); for (int i = 0; i < log_2_N; i++) { ComplexW W_ = W[i]; complex[] temp = Arrays.InitializeWithDefaultInstances <complex>(pow2); W_.w = new List <complex>(temp); for (int j = 0; j < pow2; j++) { W_.w[j] = w(j, pow2 * 2); } pow2 *= 2; } c = new complex[2, N]; for (int i = 0; i < N; i++) { c[0, i] = new complex(); c[1, i] = new complex(); } //c[0,] = Arrays.InitializeWithDefaultInstances<complex>((int)N); //c[1,] = Arrays.InitializeWithDefaultInstances<complex>((int)N); which = 0; }
public rec1() { b1field = new bool[0]; r1field = new double[0]; i1field = new int[0]; c1field = new complex[0]; b2field = new bool[0,0]; r2field = new double[0,0]; i2field = new int[0,0]; c2field = new complex[0,0]; }
public EigenObject(ILArray <complex> vec, ILArray <complex> val, int width) { Vectors = ILArray2Array(vec, width); Values = ILArray2Values(val, width); }
public EigenObject(complex[,] vec, complex[] val) { Vectors = vec; Values = val; }
/**************************************************************** * checks that matrix is Hermitian. * max|A-A^H| is calculated; if it is within 1.0E-14 of max|A|, * matrix is considered Hermitian ****************************************************************/ public static bool ishermitian(complex[,] a) { int i, j, n; double err, mx; complex v1, v2, vt; if (rows(a) != cols(a)) { return(false); } n = rows(a); if (n == 0) { return(true); } mx = 0; err = 0; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { v1 = a[i, j]; v2 = a[j, i]; if (!math.isfinite(v1.x)) { return(false); } if (!math.isfinite(v1.y)) { return(false); } if (!math.isfinite(v2.x)) { return(false); } if (!math.isfinite(v2.y)) { return(false); } vt.x = v1.x - v2.x; vt.y = v1.y + v2.y; err = Math.Max(err, math.abscomplex(vt)); mx = Math.Max(mx, math.abscomplex(v1)); mx = Math.Max(mx, math.abscomplex(v2)); } v1 = a[i, i]; if (!math.isfinite(v1.x)) { return(false); } if (!math.isfinite(v1.y)) { return(false); } err = Math.Max(err, Math.Abs(v1.y)); mx = Math.Max(mx, math.abscomplex(v1)); } if (mx == 0) { return(true); } return(err / mx <= 1.0E-14); }