/// <summary> /// GetSolution Method returning the equation solution /// </summary> /// <returns></returns> private string GetSolution() { string finalResult = ""; int size = CoefficientMatrix.RowCount; if (SolutionState == SolutionState.Unique) { for (int i = 0; i < size; i++) { double numerator = Matrix <double> .Determinant(CrammerMatrices[i], size); finalResult += i != size - 1 ? string.Format("{0} = {1:0.0} , ", VarCoefficients.ElementAt(i).Key, numerator / Determinant) : string.Format("{0} = {1:0.0}", VarCoefficients.ElementAt(i).Key, numerator / Determinant); } } else if (SolutionState == SolutionState.Infinite) { finalResult = "No Unique Solution"; } else { finalResult = "No Solution"; } return(finalResult); }
/// <summary> /// GetCoefficientMatrix Method returning the coefficient matrix of the equation /// </summary> /// <returns></returns> private Matrix <double> GetCoefficientMatrix() { int length = VarCoefficients.Keys.Count; Matrix <double> result = new Matrix <double>(length, length); for (int i = 0; i < length; i++) { for (int j = 0; j < length; j++) { result[i][j] = VarCoefficients[VarCoefficients.ElementAt(j).Key][i]; } } CoefficientParseCompletion(); return(result); }
/// <summary> /// CoefficientParseCompletion Method for completing the coefficient matrix /// </summary> private void CoefficientParseCompletion() { int length = VarCoefficients.Keys.Count; for (int i = 0; i < length; i++) { if (VarCoefficients[VarCoefficients.ElementAt(i).Key].Count != length) { int j = VarCoefficients[VarCoefficients.ElementAt(i).Key].Count; while (j < length) { VarCoefficients[VarCoefficients.ElementAt(i).Key].Add(0); j++; } } } }