Package org.opentrafficsim.core.math
Class Solver
java.lang.Object
org.opentrafficsim.core.math.Solver
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 TypeMethodDescriptionstatic 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.
-
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 x2b
- double; the coefficient of xc
- 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 solutiona
- double; quadratic coefficientb
- double; linear coefficientc
- 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 xb
- 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.
-