Пример #1
0
        /// <summary>
        /// Method for system solution verification
        /// </summary>
        /// <param name="a">System matrix</param>
        /// <param name="b">Constant terms vector</param>
        /// <param name="rowsForVariables">Equations numbers from which variables values should be calculated</param>
        /// <param name="solution">Calculated values of variables</param>
        /// <returns>Solution after verification</returns>
        private static SystemSolution CheckSolution(FieldElement[,] a, IReadOnlyList <FieldElement> b,
                                                    IReadOnlyList <int> rowsForVariables, FieldElement[] solution)
        {
            var field          = b[0].Field;
            var equationsCount = a.GetLength(0);
            var variablesCount = solution.Length;

            for (var i = 0; i < equationsCount; ++i)
            {
                var sum = field.Zero();
                for (var j = 0; j < variablesCount; ++j)
                {
                    sum += solution[j] * a[i, j];
                }
                if ((sum - b[i]).Representation != 0)
                {
                    return(SystemSolution.EmptySolution());
                }
            }

            return(solution.Where((t, i) => rowsForVariables[i] == -1).Any()
                ? SystemSolution.InfiniteSolution(solution)
                : SystemSolution.OneSolution(solution));
        }
Пример #2
0
 /// <summary>
 /// Method for checking the equality of the current solution to the <paramref name="other"/>
 /// </summary>
 /// <param name="other">Another solution</param>
 /// <returns>Checking result</returns>
 protected bool Equals(SystemSolution other)
 {
     return(_solutionsCount == other._solutionsCount &&
            (IsEmpty || VariablesValues.SequenceEqual(other.VariablesValues)));
 }