BRL-CAD

Polynomial data type. More...

Collaboration diagram for Polynomials:

Files

file  poly.h
 

Data Structures

struct  bn_multipoly
 
struct  bn_poly
 

Macros

#define BN_MAX_POLY_DEGREE   6
 
#define BN_CK_POLY(_p)   BU_CKMAG(_p, BN_POLY_MAGIC, "struct bn_poly")
 
#define BN_POLY_NULL   ((struct bn_poly *)NULL)
 
#define BN_POLY_INIT_ZERO   { BN_POLY_MAGIC, 0, {0.0} }
 

Typedefs

typedef struct bn_multipoly bn_multipoly_t
 
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)
 multiply two polynomials More...
 
struct bn_polybn_poly_scale (struct bn_poly *eqn, double factor)
 scale a polynomial More...
 
struct bn_polybn_poly_add (struct bn_poly *sum, const struct bn_poly *poly1, const struct bn_poly *poly2)
 add two polynomials More...
 
struct bn_polybn_poly_sub (struct bn_poly *diff, const struct bn_poly *poly1, const struct bn_poly *poly2)
 subtract two polynomials More...
 
void bn_poly_synthetic_division (struct bn_poly *quo, struct bn_poly *rem, const struct bn_poly *dvdend, const struct bn_poly *dvsor)
 Divides any polynomial into any other polynomial using synthetic division. Both polynomials must have real coefficients. More...
 
int bn_poly_quadratic_roots (struct bn_complex roots[], const struct bn_poly *quadrat)
 Uses the quadratic formula to find the roots (in ‘complex’ form) of any quadratic equation with real coefficients. More...
 
int bn_poly_cubic_roots (struct bn_complex roots[], const struct bn_poly *eqn)
 Uses the cubic formula to find the roots (in ‘complex’ form) of any cubic equation with real coefficients. More...
 
int bn_poly_quartic_roots (struct bn_complex roots[], const struct bn_poly *eqn)
 Uses the quartic formula to find the roots (in ‘complex’ form) of any quartic equation with real coefficients. More...
 
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)
 

Detailed Description

Polynomial data type.

Library for dealing with polynomials.

Macro Definition Documentation

◆ BN_MAX_POLY_DEGREE

#define BN_MAX_POLY_DEGREE   6

Maximum Poly Order

Definition at line 44 of file poly.h.

◆ BN_CK_POLY

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

Definition at line 56 of file poly.h.

◆ BN_POLY_NULL

#define BN_POLY_NULL   ((struct bn_poly *)NULL)

Definition at line 57 of file poly.h.

◆ BN_POLY_INIT_ZERO

#define BN_POLY_INIT_ZERO   { BN_POLY_MAGIC, 0, {0.0} }

Definition at line 58 of file poly.h.

Typedef Documentation

◆ bn_multipoly_t

typedef struct bn_multipoly bn_multipoly_t

◆ bn_poly_t

typedef struct bn_poly bn_poly_t

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

Function Documentation

◆ bn_poly_mul()

struct bn_poly * bn_poly_mul ( struct bn_poly product,
const struct bn_poly m1,
const struct bn_poly m2 
)

multiply two polynomials

bn_poly_mul

◆ bn_poly_scale()

struct bn_poly * bn_poly_scale ( struct bn_poly eqn,
double  factor 
)

scale a polynomial

bn_poly_scale

◆ bn_poly_add()

struct bn_poly * bn_poly_add ( struct bn_poly sum,
const struct bn_poly poly1,
const struct bn_poly poly2 
)

add two polynomials

bn_poly_add

◆ bn_poly_sub()

struct bn_poly * bn_poly_sub ( struct bn_poly diff,
const struct bn_poly poly1,
const struct bn_poly poly2 
)

subtract two polynomials

bn_poly_sub

◆ bn_poly_synthetic_division()

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

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

◆ bn_poly_quadratic_roots()

int bn_poly_quadratic_roots ( struct bn_complex  roots[],
const struct bn_poly quadrat 
)

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

   @return 1 for success
   @return 0 for fail.

◆ bn_poly_cubic_roots()

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

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

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.

◆ bn_poly_quartic_roots()

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

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

   @return 1 for success
   @return 0 for fail.

◆ bn_poly_findroot()

int bn_poly_findroot ( bn_poly_t eqn,
bn_complex_t nxZ,
const char *  str 
)

◆ bn_poly_eval_w_2derivatives()

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 
)

◆ bn_poly_checkroots()

int bn_poly_checkroots ( bn_poly_t eqn,
bn_complex_t roots,
int  nroots 
)

◆ bn_poly_deflate()

void bn_poly_deflate ( bn_poly_t oldP,
bn_complex_t root 
)

◆ bn_poly_roots()

int bn_poly_roots ( bn_poly_t eqn,
bn_complex_t  roots[],
const char *  name 
)

◆ bn_pr_poly()

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

Print out the polynomial.

◆ bn_pr_roots()

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

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