private LAEAnswer CalculateMatrixMethod(out List <LAEVariable> lAEVariables) { bool systemCompatible = this.CheckLinearAlgebraicEquationSystemCompatibility(); if (!systemCompatible) { lAEVariables = null; return(LAEAnswer.NoSolutions); } MatrixT <double> inversedMatrix = MatrixT <double> .GetInverseMatrix(this.Matrix); MatrixT <double> resultMatrix = inversedMatrix * new MatrixT <double>(this.RightPartEquations.ToArray()); lAEVariables = LAEVariable.FillLAEVariablesWithMatrix(resultMatrix, this.Variables); return(LAEAnswer.OneSolution); }
/// <summary> /// Initializes a new instance of the <see cref="LinearAlgebraicEquationSystem" /> class. /// </summary> /// <param name="leftPartEquations">Left part of linear algebraic equations.</param> /// <param name="rightPartEquations">Right part of linear algebraic equations.</param> /// <param name="variables">Variables of linear algebraic equations.</param> /// <param name="constants">Other constant parameters of linear algebraic equations.</param> public LinearAlgebraicEquationSystem(List <string> leftPartEquations, List <double> rightPartEquations, List <LAEVariable> variables, List <LAEVariable> constants) { if (rightPartEquations != null && rightPartEquations.Count > 0) { this.RightPartEquations = rightPartEquations; } else { throw new ArgumentException("Right parts list is null or empty!"); } List <Variable> allVariables = new List <Variable>(); if (variables != null && variables.Count > 0) { this.Variables = LAEVariable.ConvertLAEVariablesToVariables(variables); allVariables.AddRange(this.Variables); } else { throw new ArgumentException("Variables list is null or empty!"); } if (constants != null && constants.Count > 0) { this.Constants = LAEVariable.ConvertLAEVariablesToVariables(constants); allVariables.AddRange(this.Constants); } this.LeftPartEquations = new List <Expression>(); foreach (string leftPart in leftPartEquations) { this.LeftPartEquations.Add(new Expression(leftPart, allVariables)); } this.Matrix = LinearAlgebraicEquationSystem.SetMatrix(this.LeftPartEquations, this.Variables, this.Constants); }
/// <summary> /// Initializes a new instance of the <see cref="LAEVariable" /> class. /// </summary> /// <param name="initVariable">Initial variable which is supposed to be copied to the current one</param> public LAEVariable(LAEVariable initVariable) { this.Name = initVariable.Name; this.Value = initVariable.Value; }