quadratic_eqn#

rateslib.dual.quadratic_eqn(a, b, c, x0, raise_on_fail=True)#

Solve the quadratic equation, \(ax^2 + bx +c = 0\), with error reporting.

Parameters:
  • a (float, Dual Dual2) – The a coefficient value.

  • b (float, Dual Dual2) – The b coefficient value.

  • c (float, Dual Dual2) – The c coefficient value.

  • x0 (float, Dual, Dual2) – The expected solution to discriminate between two possible solutions.

  • raise_on_fail (bool, optional) – Whether to raise if unsolved or return a solver result in failed state.

Return type:

dict

Notes

If a is evaluated to be less that 1e-15 in absolute terms then it is treated as zero and the equation is solved as a linear equation in b and c only.

Examples

In [1]: from rateslib.dual import quadratic_eqn

In [2]: quadratic_eqn(a=1.0, b=1.0, c=Dual(-6.0, ["c"], []), x0=-2.9)
Out[2]: 
{'status': 'SUCCESS',
 'state': 3,
 'g': <Dual: -3.000000, (c), [0.2]>,
 'iterations': 1,
 'time': 0.0}