PLUTO  4.4-patch2
Functions
math_root_finders.c File Reference

Collection of root-finder algorithms. More...

#include "pluto.h"

Functions

int Brent (double(*Func)(double, void *), void *param, double x1, double x2, double abs_acc, double rel_acc, double *xroot)
 
int Ridder (double(*Func)(double, void *), void *param, double x1, double x2, double abs_acc, double rel_acc, double *xroot)
 
int QuadraticSolve (double a, double b, double c, double *x)
 
int CubicSolve (double b, double c, double d, double z[])
 
int QuarticSolve (double b, double c, double d, double e, double *z)
 

Detailed Description

Author
A. Mignone (migno.nosp@m.ne@t.nosp@m.o.inf.nosp@m.n.it)
Date
Aug 21, 2020

Function Documentation

◆ Brent()

int Brent ( double(*)(double, void *)  Func,
void *  param,
double  x1,
double  x2,
double  abs_acc,
double  rel_acc,
double *  xroot 
)

Use Brent's method to find the root of $ f(x) = 0$ known to lie between x1 and x2. Here the function must be in the form double Func(x,*p), where where x is the independent variable while *p is a (void) pointer to any data type containing the function parameters. Absolute accuracies can be specified to check for convergence

Parameters
[in]*funca pointer to a function func(x, *par)
[in]*parama void pointer containing the parameters
[in]x1the leftmost interval point
[in]x2the rightmost interval point
[in]abs_accthe desired absolute accuracy.(> 0 if you wish to use it).
[in]rel_accthe desired relative accuracy.(> 0 if you wish to use it).
[out]xrootthe zero of the function.
Returns
The return value is 0 on success, 1 if the root could not be found to the desired level of accurat and 2 if the the initial interval does not contain the root.

◆ CubicSolve()

int CubicSolve ( double  b,
double  c,
double  d,
double  z[] 
)

Solve a cubic equation in the form

\[ z^3 + bz^2 + cz + d = 0 \]

For its purpose, it is assumed that ALL roots are real. This makes things faster.

Parameters
[in]bcoefficient of the cubic
[in]ccoefficient of the cubic
[in]dcoefficient of the cubic
[out]zvector containing the roots of the cubic. Roots should be sorted in increasing order.

Reference:

  • Section 5.6 of Numerical Recipe
Returns
Return 0 on success.

◆ QuadraticSolve()

int QuadraticSolve ( double  a,
double  b,
double  c,
double *  x 
)

Solve a quadratic equation in the form

ax^2 + bx + c = 0

Roots are always assumed to be real and returned in x[] (exit code 0). If complex roots are found the function return exit code 1. Real roots are returned in increasing order. Reference: "Numerical Recipes in C", Press et al., Sect. 5.6

◆ QuarticSolve()

int QuarticSolve ( double  b,
double  c,
double  d,
double  e,
double *  z 
)

Solve a quartic equation in the form

\[ z^4 + bz^3 + cz^2 + dz + e = 0 \]

For its purpose, it is assumed that ALL roots are real. This makes things faster.

Parameters
[in]bcoefficient of the quartic
[in]ccoefficient of the quartic
[in]dcoefficient of the quartic
[in]ecoefficient of the quartic
[out]zvector containing the (double) roots of the quartic

Reference:

http://www.1728.com/quartic2.htm (????)

Returns
Return 0 on success, 1 if cubic solver fails, 2 if NaN has been found and 3 if quartic is not satisfied.

◆ Ridder()

int Ridder ( double(*)(double, void *)  Func,
void *  param,
double  x1,
double  x2,
double  abs_acc,
double  rel_acc,
double *  xroot 
)

Use Ridder's method to find the root of $ f(x) = 0$ known to lie between x1 and x2. Here the function must be in the form double Func(x,*p), where where x is the independent variable while *p is a (void) pointer to any data type containing the function parameters. Both relative and absolute accuracies can be specified and convergence is achieved by the condition that is realized first. To choose among the two accuracies, set the other one to a negative number.

Parameters
[in]*funca pointer to a function func(x, *par)
[in]*parama void pointer containing the parameters
[in]x1the leftmost interval point
[in]x2the rightmost interval point
[in]abs_accthe desired absolute accuracy (> 0 if you wish to use it).
[in]rel_accthe desired relative accuracy (> 0 if you wish to use it).
[out]xrootthe zero of the function.
Returns
The return value is 0 on success, 1 if the root could not be found to the desired level of accurat and 2 if the the initial interval does not contain the root.