mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
roots.hpp File Reference

Declares and defines functions for finding roots. More...

Declares and defines functions for finding roots.

Author
Jared R. Males (jared.nosp@m.male.nosp@m.s@gma.nosp@m.il.c.nosp@m.om)

Definition in file roots.hpp.

Go to the source code of this file.

Namespaces

 mx
 The mxlib c++ namespace.
 

Functions

template<typename realT >
realT mx::math::cubicDescriminant (const realT &a, const realT &b, const realT &c, const realT &d)
 Calculate the descriminant for the general cubic. More...
 
template<typename realT >
realT mx::math::cubicDescriminant (const realT &p, const realT &q)
 Calculate the descriminant for the depressed cubic. More...
 
template<typename realT >
void mx::math::cubicDepressed (realT &p, realT &q, const realT &a, const realT &b, const realT &c, const realT &d)
 Convert a general cubic equation to depressed form. More...
 
template<typename realT >
realT mx::math::cubicRealRoot (const realT &p, const realT &q)
 Calculate the real root for a depressed cubic with negative descriminant. More...
 
template<typename realT >
void mx::math::quarticRoots (std::vector< std::complex< realT > > &x, realT a, realT b, realT c, realT d, realT e)
 Find the roots of the general quartic equation. More...
 

Function Documentation

◆ cubicDepressed()

template<typename realT >
void mx::math::cubicDepressed ( realT &  p,
realT &  q,
const realT &  a,
const realT &  b,
const realT &  c,
const realT &  d 
)

Convert a general cubic equation to depressed form.

The general cubic is

\[ ax^3 + bx^2 + cx + d = 0 \]

which can be converted to compressed form

\[ t^3 + pt + q = 0 \]

Parameters
[out]pthe 1st order coefficient of the depressed cubic
[out]qthe 0th order coefficient of the depressed cubic
[in]athe 3rd order coefficient of the general cubic
[in]bthe 2nd order coefficient of the general cubic
[in]cthe 1st order coefficient of the general cubic
[in]dthe 0th order coefficient of the general cubic

Definition at line 81 of file roots.hpp.

References mx::astro::constants::c(), and mx::math::cubicDepressed().

Referenced by mx::math::cubicDepressed().

◆ cubicDescriminant() [1/2]

template<typename realT >
realT mx::math::cubicDescriminant ( const realT &  a,
const realT &  b,
const realT &  c,
const realT &  d 
)

Calculate the descriminant for the general cubic.

Returns
the descriminant
Parameters
[in]athe 3rd order coefficient of the general cubic
[in]bthe 2nd order coefficient of the general cubic
[in]cthe 1st order coefficient of the general cubic
[in]dthe 0th order coefficient of the general cubic

Definition at line 44 of file roots.hpp.

References mx::astro::constants::c(), and mx::math::cubicDescriminant().

Referenced by mx::math::cubicDescriminant().

◆ cubicDescriminant() [2/2]

template<typename realT >
realT mx::math::cubicDescriminant ( const realT &  p,
const realT &  q 
)

Calculate the descriminant for the depressed cubic.

Returns
the descriminant
Parameters
[in]pthe 0th order coefficient of the depressed cubic
[in]qthe 0th order coefficient of the depressed cubic

Definition at line 62 of file roots.hpp.

References mx::math::cubicDescriminant().

◆ cubicRealRoot()

template<typename realT >
realT mx::math::cubicRealRoot ( const realT &  p,
const realT &  q 
)

Calculate the real root for a depressed cubic with negative descriminant.

Returns
the real root for a depressed cubic defined by p and q
Exceptions
std::runtime_errorif there are 3 real roots
Parameters
[in]pthe 1st order coefficient of the depressed cubic
[in]qthe 0th order coefficient of the depressed cubic

Definition at line 101 of file roots.hpp.

References mx::math::cubicRealRoot().

Referenced by mx::math::cubicRealRoot().