private bool Swap(int i_firstIndex, int i_secondIndex) { if (i_firstIndex >= _mEquations.Count || i_secondIndex >= _mEquations.Count) { return(false); } else { LinearEquation tempEquation = _mEquations[i_firstIndex]; _mEquations[i_firstIndex] = _mEquations[i_secondIndex]; _mEquations[i_secondIndex] = tempEquation; return(true); } }
public static Tuple <LinearEquation, double, double> Deduct(LinearEquation i_firstLinEq, LinearEquation i_secondLinEq) { if (i_firstLinEq.FirstNonzeroIndex == i_secondLinEq.FirstNonzeroIndex) { int index = i_firstLinEq.FirstNonzeroIndex; double LCMultiple = LeastCommonMultiple(i_firstLinEq.GetCoeff(index), i_secondLinEq.GetCoeff(index)); double firstCoeff = LCMultiple / i_firstLinEq.GetCoeff(index); double secondCoeff = LCMultiple / i_secondLinEq.GetCoeff(index); LinearEquation equation = i_firstLinEq * firstCoeff - i_secondLinEq * secondCoeff; return(new Tuple <LinearEquation, double, double>(equation, firstCoeff, secondCoeff)); } return(null); }
private void Reduce(int i_firstIndex, int i_second_index) { var reducedEquation = LinearEquation.Deduct(_mEquations[i_firstIndex], _mEquations[i_second_index]); _mEquations[i_firstIndex] = reducedEquation.Item1; int historyIndex = i_second_index; if (SortZeroOnTop == false) { historyIndex = _mEquations.Count - historyIndex; } string _text = "Reduced: equation " + historyIndex + " * (" + reducedEquation.Item2 + ") - equation " + (historyIndex + 1) + " * (" + reducedEquation.Item3 + ")"; AddRecordToHistory(_text); }
public static List<LinearEquation> ConvertToEquations(double [,] i_matrix) { if (i_matrix.GetUpperBound(1) > 0) { var equations = new List<LinearEquation>(); for (int i = 0; i < i_matrix.GetUpperBound(0) + 1; i++) { var equation = new LinearEquation(); for (int j = 0; j < i_matrix.GetUpperBound(1); j++) { equation.AddCoeff(i_matrix[i, j]); } equation.Sum = i_matrix[i, i_matrix.GetUpperBound(1)]; equations.Add(equation); } return equations; } else return new List<LinearEquation>(); }
public static List <LinearEquation> ConvertToEquations(double [,] i_matrix) { if (i_matrix.GetUpperBound(1) > 0) { var equations = new List <LinearEquation>(); for (int i = 0; i < i_matrix.GetUpperBound(0) + 1; i++) { var equation = new LinearEquation(); for (int j = 0; j < i_matrix.GetUpperBound(1); j++) { equation.AddCoeff(i_matrix[i, j]); } equation.Sum = i_matrix[i, i_matrix.GetUpperBound(1)]; equations.Add(equation); } return(equations); } else { return(new List <LinearEquation>()); } }
public static Tuple<LinearEquation, double, double> Deduct(LinearEquation i_firstLinEq, LinearEquation i_secondLinEq) { if (i_firstLinEq.FirstNonzeroIndex == i_secondLinEq.FirstNonzeroIndex) { int index = i_firstLinEq.FirstNonzeroIndex; double LCMultiple = LeastCommonMultiple(i_firstLinEq.GetCoeff(index), i_secondLinEq.GetCoeff(index)); double firstCoeff = LCMultiple / i_firstLinEq.GetCoeff(index); double secondCoeff = LCMultiple / i_secondLinEq.GetCoeff(index); LinearEquation equation = i_firstLinEq * firstCoeff - i_secondLinEq * secondCoeff; return new Tuple<LinearEquation, double, double>(equation, firstCoeff, secondCoeff); } return null; }