Пример #1
0
        public static LinearSimultaneousEquationsSolution CalculateSolution(List <LinearEquation> coefficients, out bool invalidCoefficients)
        {
            var a = coefficients[0].XTerm;
            var b = coefficients[0].YTerm;
            var c = coefficients[0].ConstantTerm;
            var d = coefficients[1].XTerm;
            var e = coefficients[1].YTerm;
            var f = coefficients[1].ConstantTerm;

            var NaN        = Double.NaN;
            var noSolution = new LinearSimultaneousEquationsSolution(NaN, NaN, true, false);

            invalidCoefficients = false;

            if ((a == 0 && b == 0) || (d == 0 && e == 0))
            {
                invalidCoefficients = true;
                return(new LinearSimultaneousEquationsSolution(Double.NaN, Double.NaN, false, false));
            }
            else if (CheckIfParallel(coefficients))
            {
                return(GivenParallelCheckIfInfiniteSolutions(coefficients) ? ComputeInfiniteSolution(coefficients) : noSolution);
            }
            else if (a != 0)
            {
                return(new LinearSimultaneousEquationsSolution(Divide(b * f - c * e, e * a - b * d), Divide(c * d - a * f, e * a - b * d), false, false));
            }
            else if (b != 0 && d != 0)
            {
                return(new LinearSimultaneousEquationsSolution(Divide(c * e - f * b, b * d), Divide(-c, b), false, false));
            }
            else
            {
                throw new MathematicalImpossibilityException();
            }
        }
Пример #2
0
 public LinearSimultaneousEquations(List <LinearEquation> coefficients, LinearSimultaneousEquationsSolution solution)
 {
     Coefficients = coefficients;
     Solution     = solution;
 }
 protected override bool CheckValidQuestion(List <LinearEquation> coefficients, LinearSimultaneousEquationsSolution solution)
 {
     if ((coefficients[0].XTerm == 0 && coefficients[0].YTerm == 0) || (coefficients[1].XTerm == 0 && coefficients[1].YTerm == 0))
     {
         return(false);
     }
     else if (!solution.InfiniteSolutions && parameters.RequireInfiniteSolutions)
     {
         return(false);
     }
     else if (!solution.NoSolution && parameters.RequireNoSolutions)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }