Class Solver

java.lang.Object
org.opentrafficsim.core.math.Solver

public final class Solver extends Object
Solvers for simple equations.

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

Author:
Alexander Verbraeck, Peter Knoppers
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    firstSolutionAfter(double lowerBound, double a, double b, double c)
    Solve a quadratic or linear equation and return the solution that is closest (but not less than) a boundary.
    static double[]
    solve(double a, double b)
    Solve linear equation ax+b=0 for x.
    static double[]
    solve(double a, double b, double c)
    Solve quadratic equation ax2+bx+c=0 for x.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • 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 org.djunits.value.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:
      org.djunits.value.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.