public static IComplexDoubleMatrix AU(IComplexDoubleMatrix A, IROComplexDoubleVector u, int r1, int r2, int c1, int c2) { if (r2 < r1) { return(A); } return(AU(A, u, r1, r2, c1, c2, new ComplexDoubleVector(r2 - r1 + 1))); }
public static IComplexDoubleMatrix UA(IROComplexDoubleVector u, IComplexDoubleMatrix A, int r1, int r2, int c1, int c2) { if (c1 > c2) { return(A); } return(UA(u, A, r1, r2, c1, c2, new ComplexDoubleVector(c2 - c1 + 1))); }
public static ComplexDoubleVector GenerateRow(IComplexDoubleMatrix A, int r, int c1, int c2) { int cu = c2 - c1 + 1; ComplexDoubleVector u = new ComplexDoubleVector(cu); for (int j = c1; j <= c2; j++) { u[j - c1] = A[r, j]; A[r, j] = Complex.Zero; } double norm = u.GetNorm(); if (c1 == c2 || norm == 0) { A[r, c1] = new Complex(-u[0].Real, -u[0].Imag); u[0] = System.Math.Sqrt(2); return(u); } Complex scale = new Complex(1 / norm); Complex t = Complex.Zero; Complex t1 = Complex.Zero; if (u[0].Real != 0 || u[0].Imag != 0) { t = u[0]; t1 = ComplexMath.Conjugate(u[0]); t = ComplexMath.Absolute(t); t = t1 / t; scale = scale * t; } A[r, c1] = -Complex.One / scale; for (int j = 0; j < cu; j++) { u[j] *= scale; } u[0] = new Complex(u[0].Real + 1); double s = System.Math.Sqrt(1 / u[0].Real); for (int j = 0; j < cu; j++) { u[j] = new Complex(s * u[j].Real, -s * u[j].Imag); } return(u); }
public static ComplexDoubleVector GenerateColumn(IComplexDoubleMatrix A, int r1, int r2, int c) { int ru = r2 - r1 + 1; ComplexDoubleVector u = new ComplexDoubleVector(r2 - r1 + 1); for (int i = r1; i <= r2; i++) { u[i - r1] = A[i, c]; A[i, c] = Complex.Zero; } double norm = u.GetNorm(); if (r1 == r2 || norm == 0) { A[r1, c] = new Complex(-u[0]); u[0] = System.Math.Sqrt(2); return(u); } Complex scale = new Complex(1 / norm, 0); Complex t = Complex.Zero; Complex t1 = Complex.Zero; if (u[0].Real != 0 || u[0].Imag != 0) { t = u[0]; t1 = ComplexMath.Conjugate(u[0]); t = ComplexMath.Absolute(t); t = t1 / t; scale = scale * t; } A[r1, c] = -Complex.One / scale; for (int i = 0; i < ru; i++) { u[i] = u[i] * scale; } u[0] = new Complex(u[0].Real + 1, 0); double s = System.Math.Sqrt(1 / u[0].Real); for (int i = 0; i < ru; i++) { u[i] = new Complex(s * u[i].Real, s * u[i].Imag); } return(u); }
public static ComplexDoubleVector GenerateColumn(IComplexDoubleMatrix A, int r1, int r2, int c) { int ru = r2 - r1 + 1; ComplexDoubleVector u = new ComplexDoubleVector(r2 - r1 + 1); for (int i = r1; i <= r2; i++) { u[i - r1] = A[i, c]; A[i, c] = Complex.Zero; } double norm = u.GetNorm(); if (r1 == r2 || norm == 0) { A[r1, c] = new Complex(-u[0]); u[0] = System.Math.Sqrt(2); return u; } Complex scale = new Complex(1 / norm, 0); Complex t = Complex.Zero; Complex t1 = Complex.Zero; if (u[0].Real != 0 || u[0].Imag != 0) { t = u[0]; t1 = ComplexMath.Conjugate(u[0]); t = ComplexMath.Absolute(t); t = t1 / t; scale = scale * t; } A[r1, c] = -Complex.One / scale; for (int i = 0; i < ru; i++) { u[i] = u[i] * scale; } u[0] = new Complex(u[0].Real + 1, 0); double s = System.Math.Sqrt(1 / u[0].Real); for (int i = 0; i < ru; i++) { u[i] = new Complex(s * u[i].Real, s * u[i].Imag); } return u; }
public static IComplexDoubleMatrix UA(IROComplexDoubleVector u, IComplexDoubleMatrix A, int r1, int r2, int c1, int c2, IComplexDoubleVector v) { if (r2 < r1 || c2 < c1) { return(A); } if (r2 - r1 + 1 > u.Length) { throw new ArgumentException("Householder vector too short.", "u"); } if (c2 - c1 + 1 > v.Length) { throw new ArgumentException("Work vector too short.", "v"); } for (int j = c1; j <= c2; j++) { v[j - c1] = Complex.Zero; } for (int i = r1; i <= r2; i++) { for (int j = c1; j <= c2; j++) { v[j - c1] = new Complex(v[j - c1].Real + u[i - r1].Real * A[i, j].Real + u[i - r1].Imag * A[i, j].Imag, v[j - c1].Imag + u[i - r1].Real * A[i, j].Imag - u[i - r1].Imag * A[i, j].Real); } } for (int i = r1; i <= r2; i++) { for (int j = c1; j <= c2; j++) { A[i, j] = new Complex(A[i, j].Real - u[i - r1].Real * v[j - c1].Real + u[i - r1].Imag * v[j - c1].Imag, A[i, j].Imag - u[i - r1].Real * v[j - c1].Imag - u[i - r1].Imag * v[j - c1].Real); } } return(A); }
public static ComplexDoubleVector GenerateRow(IComplexDoubleMatrix A, int r, int c1, int c2) { int cu = c2 - c1 + 1; ComplexDoubleVector u = new ComplexDoubleVector(cu); for (int j = c1; j <= c2; j++) { u[j - c1] = A[r, j]; A[r, j] = Complex.Zero; } double norm = u.GetNorm(); if (c1 == c2 || norm == 0) { A[r, c1] = new Complex(-u[0].Real, -u[0].Imag); u[0] = System.Math.Sqrt(2); return u; } Complex scale = new Complex(1 / norm); Complex t = Complex.Zero; Complex t1 = Complex.Zero; if (u[0].Real != 0 || u[0].Imag != 0) { t = u[0]; t1 = ComplexMath.Conjugate(u[0]); t = ComplexMath.Absolute(t); t = t1 / t; scale = scale * t; } A[r, c1] = -Complex.One / scale; for (int j = 0; j < cu; j++) { u[j] *= scale; } u[0] = new Complex(u[0].Real + 1); double s = System.Math.Sqrt(1 / u[0].Real); for (int j = 0; j < cu; j++) { u[j] = new Complex(s * u[j].Real, -s * u[j].Imag); } return u; }
public static IComplexDoubleMatrix AU(IComplexDoubleMatrix A, IROComplexDoubleVector u, int r1, int r2, int c1, int c2) { if (r2 < r1) { return A; } return AU(A, u, r1, r2, c1, c2, new ComplexDoubleVector(r2 - r1 + 1)); }
public static IComplexDoubleMatrix AU(IComplexDoubleMatrix A, IROComplexDoubleVector u, int r1, int r2, int c1, int c2, IComplexDoubleVector v) { if (r2 < r1 || c2 < c1) { return A; } if (c2 - c1 + 1 > u.Length) { throw new ArgumentException("Householder vector too short.", "u"); } if (r2 - r1 + 1 > v.Length) { throw new ArgumentException("Work vector too short.", "v"); } for (int i = r1; i <= r2; i++) { v[i - r1] = Complex.Zero; for (int j = c1; j <= c2; j++) { v[i - r1] = new Complex(v[i - r1].Real + A[i, j].Real * u[j - c1].Real - A[i, j].Imag * u[j - c1].Imag, v[i - r1].Imag + A[i, j].Real * u[j - c1].Imag + A[i, j].Imag * u[j - c1].Real); } } for (int i = r1; i <= r2; i++) { for (int j = c1; j <= c2; j++) { A[i, j] = new Complex(A[i, j].Real - v[i - r1].Real * u[j - c1].Real - v[i - r1].Imag * u[j - c1].Imag, A[i, j].Imag + v[i - r1].Real * u[j - c1].Imag - v[i - r1].Imag * u[j - c1].Real); } } return A; }
public static IComplexDoubleMatrix UA(IROComplexDoubleVector u, IComplexDoubleMatrix A, int r1, int r2, int c1, int c2) { if (c1 > c2) { return A; } return UA(u, A, r1, r2, c1, c2, new ComplexDoubleVector(c2 - c1 + 1)); }