/// <summary> /// Gets local variables computed from given global variables, and local system of linear equations. /// </summary> /// <param name="F">Right part Vector of local system of linear equations.</param> /// <param name="G">Vector of global variables.</param> /// <returns>Vector.</returns> public Vector GetLocalVariables(Vector F, Vector G) { Vector result = new Vector(F.Size - G.Size), Fl = F.GetSubVector(2, result.Size); Matrix C, D; C = this.GetSubMatrix(2, 0, this.Rows - 2, 2); D = this.GetSubMatrix(2, 2, this.Rows - 2, this.Columns - 2); result = D.GetInverse() * (Fl - C * G); return result; }
/// <summary> /// Runs condensation on this Matrix. /// </summary> /// <param name="F">Right part Vector of local system of linear equations.</param> /// <param name="resM">Resulting Matrix.</param> /// <param name="resV">Resulting Vector.</param> public void Condensate(Vector F, out Matrix resM, out Vector resV) { if (this.Columns != this.Rows || this.Columns < 2 || this.Rows < 2) { throw new ArgumentException("Condensate method called from not square Matrix or one of it's dimensions is less then 2."); } else { resM = new Matrix(2); resV = new Vector(2); if (this.Columns == 2) { resM = this.Copy(); resV = F.Copy(); return; } Matrix A, B, C, D; Vector Fg, Fl; A = this.GetSubMatrix(0, 0, 2, 2); B = this.GetSubMatrix(0, 2, 2, this.Columns - 2); C = this.GetSubMatrix(2, 0, this.Rows - 2, 2); D = this.GetSubMatrix(2, 2, this.Rows - 2, this.Columns - 2); Fg = F.GetSubVector(0, 2); Fl = F.GetSubVector(2, F.Size - 2); resM = A - B * D.GetInverse() * C; resV = Fg - B * D.GetInverse() * Fl; } }