Class Solver


  • public final class Solver
    extends Object
    Solvers for simple equations.

    Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    Version:
    $Revision$, $LastChangedDate$, by $Author$, initial version Dec 10, 2015
    Author:
    Alexander Verbraeck, Peter Knoppers
    • Method Detail

      • solve

        public static double[] solve​(double a,
                                     double b,
                                     double c)
        Solve quadratic equation ax2+bx+c=0 for x. Degenerate case a == 0 is allowed.
        Parameters:
        a - double; the coefficient of x2
        b - double; the coefficient of x
        c - double;
        Returns:
        double[]; array with zero, one, or two elements (depending on the number of solutions of the equation)
      • firstSolutionAfter

        public static double firstSolutionAfter​(double lowerBound,
                                                double a,
                                                double b,
                                                double c)
                                         throws ValueRuntimeException
        Solve a quadratic or linear equation and return the solution that is closest (but not less than) a boundary.
        Parameters:
        lowerBound - double; minimum value of good solution
        a - double; quadratic coefficient
        b - double; linear coefficient
        c - double; value of the quadratic function for x==0
        Returns:
        double; the solution that is closest (but not less than) a boundary
        Throws:
        ValueRuntimeException - if there is no acceptable solution
      • solve

        public static double[] solve​(double a,
                                     double b)
        Solve linear equation ax+b=0 for x.
        Parameters:
        a - double; the coefficient of x
        b - double;
        Returns:
        double[]; array with one or zero elements (depending on the number of solutions of the equation). The case where both a and b are zero returns an array of length 0.