public static void NormalizeI() { for (int i = 0; i < Inm.Count; i++) { for (int j = 0; j < Inm[i].Count; j++) { Inm[i][j].Re = Math.Abs(Inm[i][j].Re); } } ComplexNumbers maxI = new ComplexNumbers(Inm[0][0]); for (int i = 0; i < Inm.Count; i++) { for (int j = 0; j < Inm[i].Count; j++) { if (Inm[i][j].Re > maxI.Re) { maxI.Re = Inm[i][j].Re; } } } for (int i = 0; i < Inm.Count; i++) { for (int j = 0; j < Inm[i].Count; j++) { Inm[i][j].Re /= maxI.Re; } } }
public static void NormalizeF() { for (int i = 0; i < matrixF.Count; i++) { for (int j = 0; j < matrixF[i].Count; j++) { matrixF[i][j].Re = Math.Abs(matrixF[i][j].Re); } } ComplexNumbers maxF = new ComplexNumbers(matrixF[0][0]); for (int i = 0; i < matrixF.Count; i++) { for (int j = 0; j < matrixF[i].Count; j++) { if (matrixF[i][j].Re > maxF.Re) { maxF.Re = matrixF[i][j].Re; } } } for (int i = 0; i < matrixF.Count; i++) { for (int j = 0; j < matrixF[i].Count; j++) { matrixF[i][j].Re /= maxF.Re; } } }
public static ComplexNumbers CalculateIntegral(double c1, double c2, double ksi1Value, double ksi2Value) { int N = SplitNumberForIntegral / 2, M = SplitNumberForIntegral / 2; double a = -1, b = 1, c = -1, d = 1; double Hx = (b - a) / (2 * N); double Hy = (d - c) / (2 * M); ComplexNumbers I = new ComplexNumbers(Hx * Hy / 9, 0); ComplexNumbers sum = new ComplexNumbers(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { sum += Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i, 2 * j) + Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i + 2, 2 * j) + Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i, 2 * j + 2) + Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i + 2, 2 * j + 2) + 4 * Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i + 1, 2 * j) + 4 * Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i, 2 * j + 1) + 4 * Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i + 2, 2 * j + 1) + 4 * Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i + 1, 2 * j + 2) + 16 * Fxy(c1, c2, ksi1Value, ksi2Value, 2 * i + 1, 2 * j + 1); } } // ComplexNumbers res = new ComplexNumbers(I * sum * (new ComplexNumbers(1, 0) / (new ComplexNumbers(2, 0)*new ComplexNumbers(CalculateAlpha(c1, c2), 0) * new ComplexNumbers(CalculateAlpha(c1, c2), 0)))); ComplexNumbers res = new ComplexNumbers(I * sum * (new ComplexNumbers(2, 0) / (new ComplexNumbers(CalculateAlpha(c1, c2), 0)))); return(res); }
private static ComplexNumbers ComputeIntegralForI(double ksi1, double ksi2) { ComplexNumbers result = new ComplexNumbers(); for (int n = -_n; n <= _n; n++) { for (int m = -_m; m <= _m; m++) { result += new ComplexNumbers(Math.Cos(-_c1 * n * ksi1 - _c2 * m * ksi2), Math.Sin(-_c1 * n * ksi1 - _c2 * m * ksi2)); } } return(result); }
private static ComplexNumbers ComputeIntegralForKsi(double ksi1, double ksi2) { ComplexNumbers result = new ComplexNumbers(); for (int n = -_n; n <= _n; n++) { for (int m = -_m; m <= _m; m++) { result += new ComplexNumbers(-Math.Cos(_c1 * n * (ksi1 - 1) + _c2 * m * (ksi2 - 1)) + Math.Cos(_c1 * n * (ksi1 + 1) + _c2 * m * (ksi2 - 1)) + Math.Cos(_c1 * n * (ksi1 - 1) + _c2 * m * (ksi2 + 1)) - Math.Cos(_c1 * n * (ksi1 + 1) + _c2 * m * (ksi2 + 1)), -Math.Sin(_c1 * n * (ksi1 - 1) + _c2 * m * (ksi2 - 1)) + Math.Sin(_c1 * n * (ksi1 + 1) + _c2 * m * (ksi2 - 1)) + Math.Sin(_c1 * n * (ksi1 - 1) + _c2 * m * (ksi2 + 1)) - Math.Sin(_c1 * n * (ksi1 + 1) + _c2 * m * (ksi2 + 1))) * new ComplexNumbers(_c1 * _c2 * n * m, 0); } } return(result); }
public static ComplexNumbers FxNewton(double c1, double c2) { ComplexNumbers[,] a = new ComplexNumbers[SplitNumberForIntegral, SplitNumberForIntegral]; for (int i = 0; i < SplitNumberForIntegral; i++) { for (int j = 0; j < SplitNumberForIntegral; j++) { a[i, j] = CalculateIntegral(c1, c2, ksi1[i], ksi1[j]); } } return(Det(a)); }
public static ComplexNumbers Det(ComplexNumbers[,] A) { KeyValuePair <ComplexNumbers[, ], ComplexNumbers[, ]> lu = LU(A); int n = A.GetLength(0); ComplexNumbers det1 = new ComplexNumbers(1, 0); ComplexNumbers det2 = new ComplexNumbers(1, 0); for (int i = 0; i < n; i++) { det1 *= lu.Key[i, i]; det2 *= lu.Value[i, i]; } return(det1 * det2); }
public static ComplexNumbers[,] PoxidnaMatrix(double c1, double c2) { double delta = 0.001; ComplexNumbers[,] a = new ComplexNumbers[SplitNumberForIntegral, SplitNumberForIntegral]; for (int i = 0; i < SplitNumberForIntegral; i++) { for (int j = 0; j < SplitNumberForIntegral; j++) { a[i, j] = (CalculateIntegral(c1, c2 + delta, ksi1[i], ksi1[j]) - CalculateIntegral(c1, c2, ksi1[i], ksi1[j])) / new ComplexNumbers(delta, 0); } } return(a); }
private void Form1_Load(object sender, EventArgs e) { Bitmap bm = new Bitmap(pictureBox1.Width, pictureBox1.Height); // Relevant Math // Where a is real and bi is imaginary // (a +bi)^2 represents your (a) real coordinate and (bi) your imaginary coordiante // (a + bi)^2 = a^2 + bi^2 + 2abi // (a^2 - b^2) + (2abi) where (a^2 + b^2) is purely real and (2abi) is purely imaginary // Starting a 0 (z) and the complez number (c) to z // f(z) = z^2 +c // The new value of z should be the old value of z squared plus c for (int x = 0; x < pictureBox1.Width; x++) { for (int y = 0; y < pictureBox1.Height; y++) { double a = (double)(x - (pictureBox1.Width / 2)) / (double)(pictureBox1.Width / 4); double b = (double)(y - (pictureBox1.Height / 2)) / (double)(pictureBox1.Height / 4); ComplexNumbers c = new ComplexNumbers(a, b); ComplexNumbers z = new ComplexNumbers(0, 0); // Initial iterarion int it = 0; do { it++; z.Square(); z.Add(c); if (z.Magnitude() > 2.0) { break; } } // Number of iterations while (it < 100); bm.SetPixel(x, y, it < 100 ? Color.Red : Color.Blue); } } pictureBox1.Image = bm; }
public static ComplexNumbers GetK(double integralKsi1, double integralKsi2, double Ksi1, double Ksi2) { ComplexNumbers sum = new ComplexNumbers(); for (int n = -N; n <= N; n++) { for (int m = -M; m <= M; m++) { double val = c1 * n * (Ksi1 - integralKsi1) + c2 * m * ((Ksi2 - integralKsi2)); sum += new ComplexNumbers { Re = Math.Cos(val), Im = Math.Sin(val) }; } } return(sum); }
public static ComplexNumbers Fxy(double c1, double c2, double ksi1Value, double ksi2Value, int i, int j) { double x = ksi1[i]; double y = ksi2[j]; ComplexNumbers sum = new ComplexNumbers(); for (int n = -N; n <= N; n++) { for (int m = -M; m <= M; m++) { sum += new ComplexNumbers { Re = Math.Cos(c1 * n * (ksi1Value - x) + c2 * m * ((ksi2Value - y))), Im = Math.Sin(c1 * n * (ksi1Value - x) + c2 * m * ((ksi2Value - y))) }; } } return(sum); }
public static KeyValuePair <ComplexNumbers[, ], ComplexNumbers[, ]> LU(ComplexNumbers[,] A) { int n = A.GetLength(0); ComplexNumbers[,] L = new ComplexNumbers[n, n]; ComplexNumbers[,] U = new ComplexNumbers[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { U[0, i] = A[0, i]; L[i, 0] = A[i, 0] / U[0, 0]; ComplexNumbers sum = new ComplexNumbers(); for (int k = 0; k < i; k++) { sum += L[i, k] * U[k, j]; } U[i, j] = A[i, j] - sum; if (i > j) { L[j, i] = new ComplexNumbers(); } else { sum = new ComplexNumbers(); for (int k = 0; k < i; k++) { sum += L[j, k] * U[k, i]; } L[j, i] = (A[j, i] - sum) / U[i, i]; } } } KeyValuePair <ComplexNumbers[, ], ComplexNumbers[, ]> result = new KeyValuePair <ComplexNumbers[, ], ComplexNumbers[, ]>(L, U); return(result); }
public static ComplexNumbers CalculateIntegralI(int n, int m) { //reshitka double a = -1, b = 1, c = -1, d = 1; double Hx = (b - a) / (2 * N); double Hy = (d - c) / (2 * M); ComplexNumbers I = new ComplexNumbers(Hx * Hy / 9.0, 0); ComplexNumbers sum = new ComplexNumbers(); for (int i = 0; i < SplitNumberForIntegral / 2; i++) { for (int j = 0; j < SplitNumberForIntegral / 2; j++) { sum += GetValueUnerIntegralFunctionI(2 * i, 2 * j, n, m) + GetValueUnerIntegralFunctionI(2 * i + 2, 2 * j, n, m) + GetValueUnerIntegralFunctionI(2 * i, 2 * j + 2, n, m) + GetValueUnerIntegralFunctionI(2 * i + 2, 2 * j + 2, n, m) + 4 * GetValueUnerIntegralFunctionI(2 * i + 1, 2 * j, n, m) + 4 * GetValueUnerIntegralFunctionI(2 * i, 2 * j + 1, n, m) + 4 * GetValueUnerIntegralFunctionI(2 * i + 2, 2 * j + 1, n, m) + 4 * GetValueUnerIntegralFunctionI(2 * i + 1, 2 * j + 2, n, m) + 16 * GetValueUnerIntegralFunctionI(2 * i + 1, 2 * j + 1, n, m); } } return(I * sum); }
public static AntennasRadiationPatternProblemResult Calculate(Problem problem) { _m = problem.M1; _n = problem.M2; _c1 = problem.C1; _c2 = problem.C2; _modF = Convert.ToDouble(problem.FModule.Replace(".", ",")); _argF = Convert.ToDouble(problem.FArgument.Replace(".", ",")); /*****************************************************************************************/ List <List <ComplexNumbers> > I = new List <List <ComplexNumbers> >(); for (int i = 0; i < 11; i++) { I.Add(new List <ComplexNumbers>()); } ComplexNumbers alpha = new ComplexNumbers(Math.Pow(2 * Math.PI, 2) / (_c1 * _c2), 0); ComplexNumbers p = new ComplexNumbers(1, 0); double limitWidth = 1; double limitHeight = 1; List <List <ComplexNumbers> > lastF = new List <List <ComplexNumbers> >(); ComplexNumbers maxF = new ComplexNumbers(); double step = problem.Eps < 0.01 ? problem.Eps : 0.01;//limitHeight / M; for (double i = -limitWidth; i <= limitWidth; i += step) { lastF.Add(new List <ComplexNumbers>()); for (double j = -limitHeight; j <= limitHeight; j += step) { ComplexNumbers fPrev = new ComplexNumbers(_modF * Math.Cos(_argF), _modF * Math.Sin(_argF)); ComplexNumbers F; ComplexNumbers D; double amountStepsForKsi1 = 10; double amountStepsForKsi2 = 10; double hksi1 = (limitHeight * 2) / (2 * amountStepsForKsi1); // (b-a)/2N double hksi2 = (limitWidth * 2) / (2 * amountStepsForKsi2); // (d-c)/2M ComplexNumbers kFor2 = new ComplexNumbers(); for (int k = 0; k < amountStepsForKsi1; k++) { for (int l = 0; l < amountStepsForKsi2; l++) { kFor2 += (ComputeIntegralForKsiInPow(2 * k * hksi1, 2 * l * hksi2) + ComputeIntegralForKsiInPow((2 * k + 2) * hksi1, 2 * l * hksi2) + ComputeIntegralForKsiInPow(2 * k * hksi1, (2 * l + 2) * hksi2) + ComputeIntegralForKsiInPow((2 * k + 2) * hksi1, (2 * l + 2) * hksi2) + new ComplexNumbers(4.0, 0) * (ComputeIntegralForKsiInPow((2 * k + 1) * hksi1, 2 * l * hksi2) + ComputeIntegralForKsiInPow(2 * k * hksi1, (2 * l + 1) * hksi2) + ComputeIntegralForKsiInPow((2 * k + 2) * hksi1, (2 * l + 1) * hksi2) + ComputeIntegralForKsiInPow((2 * k + 1) * hksi1, (2 * l + 2) * hksi2)) + new ComplexNumbers(16.0, 0) * ComputeIntegralForKsiInPow((2 * k + 1) * hksi1, (2 * l + 1) * hksi2)); } } kFor2 *= new ComplexNumbers((hksi1 * hksi2) / 9.0, 0); var ab = kFor2 * (p - fPrev.GetModule().GetPow()) * fPrev.GetPow(); var a2 = kFor2 * (p - fPrev.GetModule().GetPow()).GetPow() * fPrev.GetPow(); var b2 = kFor2 * fPrev.GetPow(); D = new ComplexNumbers(16, 0) * ab.GetPow() - new ComplexNumbers(4, 0) * b2 * (a2 - alpha.GetPow() * p); ComplexNumbers l1 = (new ComplexNumbers(-4, 0) * ab + D.GetSqrt()) / (new ComplexNumbers(2, 0) * b2); ComplexNumbers l2 = (new ComplexNumbers(-4, 0) * ab - D.GetSqrt()) / (new ComplexNumbers(2, 0) * b2); ComplexNumbers lambda; if (l2.GetModule() > l1.GetModule()) { lambda = l1; } else { lambda = l2; } ComplexNumbers a = ComputeIntegralForKsi(i, j) * (p - fPrev.GetModule().GetPow()) * fPrev; ComplexNumbers b = ComputeIntegralForKsi(i, j) * fPrev; F = (new ComplexNumbers(2, 0) * a + lambda * b) / alpha; if (i >= -1.1 && i <= 1.1 && j >= -1.1 && j <= 1.1) { ComplexNumbers kForI = new ComplexNumbers(); for (int k = 0; k < amountStepsForKsi1; k++) { for (int l = 0; l < amountStepsForKsi2; l++) { kForI += (ComputeIntegralForI(2 * k * hksi1, 2 * l * hksi2) + ComputeIntegralForI((2 * k + 2) * hksi1, 2 * l * hksi2) + ComputeIntegralForI(2 * k * hksi1, (2 * l + 2) * hksi2) + ComputeIntegralForI((2 * k + 2) * hksi1, (2 * l + 2) * hksi2) + new ComplexNumbers(4.0, 0) * (ComputeIntegralForI((2 * k + 1) * hksi1, 2 * l * hksi2) + ComputeIntegralForI(2 * k * hksi1, (2 * l + 1) * hksi2) + ComputeIntegralForI((2 * k + 2) * hksi1, (2 * l + 1) * hksi2) + ComputeIntegralForI((2 * k + 1) * hksi1, (2 * l + 2) * hksi2)) + new ComplexNumbers(16.0, 0) * ComputeIntegralForI((2 * k + 1) * hksi1, (2 * l + 1) * hksi2)); } } kForI *= new ComplexNumbers((hksi1 * hksi2) / 9.0, 0); int index = Convert.ToInt32((1.0 + i) / 0.2); I[index].Add((p - F.GetModule().GetPow()) * F * kForI + lambda * F * kForI); } if (F > maxF) { maxF = F; } lastF[lastF.Count - 1].Add(F); } } var maxI = I[0][0]; for (int i = 0; i < I.Count; i++) { for (int j = 0; j < I[i].Count; j++) { if (maxI < I[i][j]) { maxI = I[i][j]; } } } var result = new AntennasRadiationPatternProblemResult(); result.I = new double[I.Count][]; for (int i = 0; i < I.Count; i++) { result.I[i] = new double[I[i].Count]; for (int j = 0; j < I[i].Count; j++) { result.I[i][j] = (I[i][j] / maxI).GetModule().Re; } } result.F = new double[lastF.Count][]; for (int i = 0; i < lastF.Count; i++) { result.F[i] = new double[lastF.Count]; for (int j = 0; j < lastF[i].Count; j++) { result.F[i][j] = (lastF[i][j] / maxF).GetModule().Re; } } return(result); }
private static ComplexNumbers FxNewtonPox(double c1, double c2) { // D = LU // B = MU + LV int n = SplitNumberForIntegral; ComplexNumbers[,] D = new ComplexNumbers[n, n]; for (int i = 0; i < SplitNumberForIntegral; i++) { for (int j = 0; j < SplitNumberForIntegral; j++) { D[i, j] = CalculateIntegral(c1, c2, ksi1[i], ksi1[j]); } } ComplexNumbers[,] B = PoxidnaMatrix(c1, c2); ComplexNumbers[,] L = new ComplexNumbers[n, n]; for (int i = 0; i < n; i++) { L[i, i] = new ComplexNumbers(1, 0); } ComplexNumbers[,] U = new ComplexNumbers[n, n]; ComplexNumbers[,] V = new ComplexNumbers[n, n]; ComplexNumbers[,] M = new ComplexNumbers[n, n]; for (int r = 0; r < n; r++) { for (int k = r; k < n; k++) { ComplexNumbers sumU = new ComplexNumbers(0, 0.0); ComplexNumbers sumV = new ComplexNumbers(0, 0.0); for (int j = 0; j < r; j++) { sumU += L[r, j] * U[j, k]; sumV += M[r, j] * U[j, k] + L[r, j] * V[j, k]; } U[r, k] = D[r, k] - sumU; V[r, k] = B[r, k] - sumV; } for (int i = r + 1; i < n; i++) { ComplexNumbers sumL = new ComplexNumbers(0, 0.0); ComplexNumbers sumM = new ComplexNumbers(0, 0.0); for (int j = 0; j < r; j++) { sumL = sumL + (L[i, j] * U[j, r]); sumM = sumM + (M[i, j] * U[j, r] + L[i, j] * V[j, r]); } L[i, r] = (D[i, r] - sumL) / U[r, r]; M[i, r] = (B[i, r] - sumM - L[i, r] * V[r, r]) / U[r, r]; } } ComplexNumbers detB = new ComplexNumbers(0, 0.0); for (int i = 0; i < n; i++) { ComplexNumbers sum = V[i, i]; for (int k = 0; k < n; k++) { if (k != i) { sum *= U[k, k]; } } detB += sum; } return(detB); }