static void Main(string[] args) { Matrix <int> m = new Matrix <int>(2, 2); m[0, 0] = 2; m[1, 1] = 2; m[0, 1] = 12; Console.WriteLine(m[0, 0]); Console.ReadKey(); Matrix <int> m2 = new Matrix <int>(2, 2); m2[0, 0] = 1; m2[1, 1] = 2; var m3 = m * m2; Console.WriteLine("a = \r\n" + m); Console.WriteLine("b = \r\n" + m2); Console.WriteLine("a * b = \r\n" + m3); Console.WriteLine(); Console.WriteLine(Matrix <int> .Adjoint(m).ToString()); Console.ReadKey(); var v1 = new Vector <double>(new List <double> { 1, 1, 1 }); var v2 = new Vector <double>(new List <double> { 1, 2, 1 }); var v3 = new Vector <double>(new List <double> { -4, 3, 1 }); Console.WriteLine("v1: " + v1.ToString()); Console.WriteLine("v2: " + v2.ToString()); Console.WriteLine("v3: " + v3.ToString()); var vects = new List <Vector <double> > { v1, v2, v3 }; var orthoVects = GramSchmidt <double> .Orthogonalize(vects); var orthoNormVects = GramSchmidt <double> .Normalize(orthoVects); foreach (var v in orthoNormVects) { Console.WriteLine(v); } Console.ReadKey(); }
public void When_Transpose_Q(int size) { // Arrange Random device = new Random(); Matrix A = new Matrix(size, size); Matrix I = new Matrix(size, size); for (int i = 0; i < size; i++) { I.Elem[i][i] = 1; for (int j = 0; j < size; j++) { A.Elem[i][j] = device.NextDouble(); } } Matrix Q1 = new Matrix(A.Row, A.Column); Matrix R1 = new Matrix(A.Row, A.Column); Matrix Q2 = new Matrix(A.Row, A.Column); Matrix R2 = new Matrix(A.Row, A.Column); Matrix Q3 = new Matrix(A.Row, A.Column); Matrix R3 = new Matrix(A.Row, A.Column); for (int i = 0; i < A.Row; i++) { Q3.Elem[i][i] = 1.0; } Matrix Q4 = new Matrix(A.Row, A.Column); Matrix R4 = new Matrix(A.Row, A.Column); for (int i = 0; i < A.Row; i++) { Q4.Elem[i][i] = 1.0; } GramSchmidt.Classic(A, Q1, R1); GramSchmidt.Modified(A, Q2, R2); Givens.Orthogon(A, Q3, R3); Householder.Orthogon(A, Q4, R4); // Act Matrix QT1 = Q1.Transpose(); Matrix QT2 = Q2.Transpose(); Matrix QT3 = Q3.Transpose(); Matrix QT4 = Q4.Transpose(); // Assert Assert.That(QT1 * Q1 == I); Assert.That(QT2 * Q2 == I); Assert.That(QT3 * Q3 == I); Assert.That(QT4 * Q4 == I); }
public void When_Solve_ORT() { // Arrange Matrix A = new Matrix(3, 3); A.Elem[0][0] = 2; A.Elem[0][1] = 3; A.Elem[0][2] = -1; A.Elem[1][0] = 1; A.Elem[1][1] = -2; A.Elem[1][2] = 1; A.Elem[2][0] = 1; A.Elem[2][1] = 0; A.Elem[2][2] = 2; Vector F = new Vector(3); F.Elem[0] = 9; F.Elem[1] = 3; F.Elem[2] = 2; // Act Vector gramSchmidtC = GramSchmidt.StartModifiedSolverQR(A, F); Vector gramSchmidtM = GramSchmidt.StartModifiedSolverQR(A, F); Vector givens = Givens.StartSolverQR(A, F); Vector householder = Householder.StartSolverQR(A, F); // Assert Assert.That(A * gramSchmidtC == F); Assert.That(A * gramSchmidtM == F); Assert.That(A * givens == F); Assert.That(A * householder == F); }
/// <summary> /// Computes the QR decomposition for a matrix using Modified Gram-Schmidt Orthogonalization. /// </summary> /// <param name="matrix">The matrix to factor.</param> /// <returns>The QR decomposition object.</returns> public static GramSchmidt GramSchmidt(this Matrix <double> matrix) { return((GramSchmidt)GramSchmidt <double> .Create(matrix)); }
/// <summary> /// Computes the QR decomposition for a matrix using Modified Gram-Schmidt Orthogonalization. /// </summary> /// <param name="matrix">The matrix to factor.</param> /// <returns>The QR decomposition object.</returns> public static GramSchmidt GramSchmidt(this Matrix <Complex> matrix) { return((GramSchmidt)GramSchmidt <Complex> .Create(matrix)); }
/// <summary> /// Computes the QR decomposition for a matrix using Modified Gram-Schmidt Orthogonalization. /// </summary> /// <param name="matrix">The matrix to factor.</param> /// <returns>The QR decomposition object.</returns> public static GramSchmidt GramSchmidt(this Matrix <float> matrix) { return((GramSchmidt)GramSchmidt <float> .Create(matrix)); }