Polynomials
[libbn (numerical functions)]

Collaboration diagram for Polynomials:

Data Structures

struct  bn_poly

Files

file  poly.c

Defines

#define BN_MAX_POLY_DEGREE   4
#define BN_CK_POLY(_p)   BU_CKMAG(_p, BN_POLY_MAGIC, "struct bn_poly")
#define BN_POLY_NULL   ((struct bn_poly *)NULL)
#define Max(a, b)   ((a) > (b) ? (a) : (b))
#define PI_DIV_3   (M_PI/3.0)
#define SQRT3   1.732050808
#define THIRD   0.333333333333333333333333333
#define INV_TWENTYSEVEN   0.037037037037037037037037037
#define CUBEROOT(a)   (((a) >= 0.0) ? pow(a, THIRD) : -pow(-(a), THIRD))

Typedefs

typedef struct bn_poly bn_poly_t

Functions

struct bn_polybn_poly_mul (struct bn_poly *product, const struct bn_poly *m1, const struct bn_poly *m2)
struct bn_polybn_poly_scale (struct bn_poly *eqn, double factor)
struct bn_polybn_poly_add (struct bn_poly *sum, const struct bn_poly *poly1, const struct bn_poly *poly2)
struct bn_polybn_poly_sub (struct bn_poly *diff, const struct bn_poly *poly1, const struct bn_poly *poly2)
void bn_poly_synthetic_division (struct bn_poly *quo, struct bn_poly *rem, const struct bn_poly *dvdend, const struct bn_poly *dvsor)
int bn_poly_quadratic_roots (struct bn_complex roots[], const struct bn_poly *quadrat)
int bn_poly_cubic_roots (struct bn_complex roots[], const struct bn_poly *eqn)
int bn_poly_quartic_roots (struct bn_complex roots[], const struct bn_poly *eqn)
int bn_poly_findroot (bn_poly_t *eqn, bn_complex_t *nxZ, const char *str)
void bn_poly_eval_w_2derivatives (bn_complex_t *cZ, bn_poly_t *eqn, bn_complex_t *b, bn_complex_t *c, bn_complex_t *d)
int bn_poly_checkroots (bn_poly_t *eqn, bn_complex_t *roots, int nroots)
void bn_poly_deflate (bn_poly_t *oldP, bn_complex_t *root)
int bn_poly_roots (bn_poly_t *eqn, bn_complex_t roots[], const char *name)
void bn_pr_poly (const char *title, const struct bn_poly *eqn)
void bn_pr_roots (const char *title, const struct bn_complex roots[], int n)
HIDDEN void bn_catch_FPE (int sig)
struct bn_polybn_poly_mul (register struct bn_poly *product, register const struct bn_poly *m1, register const struct bn_poly *m2)
 multiply two polynomials
struct bn_polybn_poly_scale (register struct bn_poly *eqn, double factor)
 scale a polynomial
struct bn_polybn_poly_add (register struct bn_poly *sum, register const struct bn_poly *poly1, register const struct bn_poly *poly2)
 add two polynomials
struct bn_polybn_poly_sub (register struct bn_poly *diff, register const struct bn_poly *poly1, register const struct bn_poly *poly2)
 subtract two polynomials
void bn_poly_synthetic_division (register struct bn_poly *quo, register struct bn_poly *rem, register const struct bn_poly *dvdend, register const struct bn_poly *dvsor)
 Divides any polynomial into any other polynomial using synthetic division. Both polynomials must have real coefficients.
int bn_poly_quadratic_roots (register struct bn_complex *roots, register const struct bn_poly *quadrat)
 Uses the quadratic formula to find the roots (in `complex' form) of any quadratic equation with real coefficients.
int bn_poly_cubic_roots (register struct bn_complex *roots, register const struct bn_poly *eqn)
 Uses the cubic formula to find the roots (in `complex' form) of any cubic equation with real coefficients.
int bn_poly_quartic_roots (register struct bn_complex *roots, register const struct bn_poly *eqn)
 Uses the quartic formula to find the roots (in `complex' form) of any quartic equation with real coefficients.
void bn_pr_poly (const char *title, register const struct bn_poly *eqn)
void bn_pr_roots (const char *title, const struct bn_complex *roots, int n)

Detailed Description


Define Documentation

#define BN_MAX_POLY_DEGREE   4

Maximum Poly Order

Definition at line 1008 of file bn.h.

Referenced by bn_poly_mul().

#define BN_CK_POLY ( _p   )     BU_CKMAG(_p, BN_POLY_MAGIC, "struct bn_poly")

Definition at line 1018 of file bn.h.

#define BN_POLY_NULL   ((struct bn_poly *)NULL)

Definition at line 1019 of file bn.h.

Referenced by bn_poly_mul().

#define Max ( a,
 )     ((a) > (b) ? (a) : (b))

Definition at line 39 of file poly.c.

#define PI_DIV_3   (M_PI/3.0)

Definition at line 41 of file poly.c.

Referenced by bn_poly_cubic_roots().

#define SQRT3   1.732050808

Definition at line 43 of file poly.c.

Referenced by bn_poly_cubic_roots().

#define THIRD   0.333333333333333333333333333

Definition at line 44 of file poly.c.

Referenced by bn_poly_cubic_roots().

#define INV_TWENTYSEVEN   0.037037037037037037037037037

Definition at line 45 of file poly.c.

Referenced by bn_poly_cubic_roots().

#define CUBEROOT (  )     (((a) >= 0.0) ? pow(a, THIRD) : -pow(-(a), THIRD))

Definition at line 46 of file poly.c.

Referenced by bn_poly_cubic_roots().


Typedef Documentation

typedef struct bn_poly bn_poly_t

Polynomial data type bn_poly->cf[n] corresponds to X^n


Function Documentation

struct bn_poly* bn_poly_mul ( struct bn_poly product,
const struct bn_poly m1,
const struct bn_poly m2 
) [read]
struct bn_poly* bn_poly_scale ( struct bn_poly eqn,
double  factor 
) [read]
struct bn_poly* bn_poly_add ( struct bn_poly sum,
const struct bn_poly poly1,
const struct bn_poly poly2 
) [read]
struct bn_poly* bn_poly_sub ( struct bn_poly diff,
const struct bn_poly poly1,
const struct bn_poly poly2 
) [read]
void bn_poly_synthetic_division ( struct bn_poly quo,
struct bn_poly rem,
const struct bn_poly dvdend,
const struct bn_poly dvsor 
)
int bn_poly_quadratic_roots ( struct bn_complex  roots[],
const struct bn_poly quadrat 
)

Referenced by bn_poly_quartic_roots().

int bn_poly_cubic_roots ( struct bn_complex  roots[],
const struct bn_poly eqn 
)

Referenced by bn_poly_quartic_roots().

int bn_poly_quartic_roots ( struct bn_complex  roots[],
const struct bn_poly eqn 
)
int bn_poly_findroot ( bn_poly_t eqn,
bn_complex_t nxZ,
const char *  str 
)
void bn_poly_eval_w_2derivatives ( bn_complex_t cZ,
bn_poly_t eqn,
bn_complex_t b,
bn_complex_t c,
bn_complex_t d 
)
int bn_poly_checkroots ( bn_poly_t eqn,
bn_complex_t roots,
int  nroots 
)
void bn_poly_deflate ( bn_poly_t oldP,
bn_complex_t root 
)
int bn_poly_roots ( bn_poly_t eqn,
bn_complex_t  roots[],
const char *  name 
)
void bn_pr_poly ( const char *  title,
const struct bn_poly eqn 
)
void bn_pr_roots ( const char *  title,
const struct bn_complex  roots[],
int  n 
)
HIDDEN void bn_catch_FPE ( int  sig  ) 

Definition at line 53 of file poly.c.

Referenced by bn_poly_cubic_roots().

struct bn_poly* bn_poly_mul ( register struct bn_poly product,
register const struct bn_poly m1,
register const struct bn_poly m2 
) [read]

multiply two polynomials

bn_poly_mul

Definition at line 71 of file poly.c.

References BN_MAX_POLY_DEGREE, BN_POLY_NULL, bn_poly::cf, and bn_poly::dgr.

struct bn_poly* bn_poly_scale ( register struct bn_poly eqn,
double  factor 
) [read]

scale a polynomial

bn_poly_scale

Definition at line 125 of file poly.c.

References bn_poly::cf, and bn_poly::dgr.

struct bn_poly* bn_poly_add ( register struct bn_poly sum,
register const struct bn_poly poly1,
register const struct bn_poly poly2 
) [read]

add two polynomials

bn_poly_add

Definition at line 142 of file poly.c.

References bn_poly::cf, and bn_poly::dgr.

struct bn_poly* bn_poly_sub ( register struct bn_poly diff,
register const struct bn_poly poly1,
register const struct bn_poly poly2 
) [read]

subtract two polynomials

bn_poly_sub

Definition at line 176 of file poly.c.

References bn_poly::cf, and bn_poly::dgr.

void bn_poly_synthetic_division ( register struct bn_poly quo,
register struct bn_poly rem,
register const struct bn_poly dvdend,
register const struct bn_poly dvsor 
)

Divides any polynomial into any other polynomial using synthetic division. Both polynomials must have real coefficients.

s y n D i v

Definition at line 213 of file poly.c.

References bn_poly::cf, bn_poly::dgr, and n.

int bn_poly_quadratic_roots ( register struct bn_complex roots,
register const struct bn_poly quadrat 
)

Uses the quadratic formula to find the roots (in `complex' form) of any quadratic equation with real coefficients.

b n _ p o l y _ q u a d r a t i c _ r o o t s

Returns:
1 for success
0 for fail.

Definition at line 252 of file poly.c.

References bn_poly::cf, bn_complex::im, NEAR_ZERO, and bn_complex::re.

int bn_poly_cubic_roots ( register struct bn_complex roots,
register const struct bn_poly eqn 
)

Uses the cubic formula to find the roots (in `complex' form) of any cubic equation with real coefficients.

b n _ p o l y _ c u b i c _ r o o t s to solve a polynomial of the form:

X**3 + c1*X**2 + c2*X + c3 = 0,

first reduce it to the form:

Y**3 + a*Y + b = 0,

where Y = X + c1/3, and a = c2 - c1**2/3, b = (2*c1**3 - 9*c1*c2 + 27*c3)/27.

Then we define the value delta, D = b**2/4 + a**3/27.

If D > 0, there will be one real root and two conjugate complex roots. If D = 0, there will be three real roots at least two of which are equal. If D < 0, there will be three unequal real roots.

Returns 1 for success, 0 for fail.

Definition at line 342 of file poly.c.

References A, bn_catch_FPE(), bn_poly::cf, CUBEROOT, bn_complex::im, INV_TWENTYSEVEN, PI_DIV_3, bn_complex::re, SQRT3, THIRD, and ZERO.

Here is the call graph for this function:

int bn_poly_quartic_roots ( register struct bn_complex roots,
register const struct bn_poly eqn 
)

Uses the quartic formula to find the roots (in `complex' form) of any quartic equation with real coefficients.

b n _ p o l y _ q u a r t i c _ r o o t s

Returns:
1 for success
0 for fail.

Definition at line 449 of file poly.c.

References bn_poly_cubic_roots(), bn_poly_quadratic_roots(), bn_poly::cf, bn_poly::dgr, Max3, NEAR_ZERO, and ZERO.

Here is the call graph for this function:

void bn_pr_poly ( const char *  title,
register const struct bn_poly eqn 
)

b n _ p r _ p o l y

Print out the polynomial.

Definition at line 533 of file poly.c.

References bn_poly::cf, bn_poly::dgr, and n.

void bn_pr_roots ( const char *  title,
const struct bn_complex roots,
int  n 
)

b n _ p r _ r o o t s

Print out the roots of a given polynomial (complex numbers)

Definition at line 577 of file poly.c.

Generated on Tue Dec 11 13:14:29 2012 for LIBBN by  doxygen 1.6.3