The methods in this class are static methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Exception to indicate that the polynomial passed tointegrateRootP4(Polynomial,double,double)
has a factor with whose minimum value is close to zero. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
add
(double[] result, double[] p1, int n1, double[] p2, int n2) Add two polynomials p1(x) and p2(x) given their coefficients.static int
add
(double[] result, double[] p1, int n1, double[] p2, int n2, boolean prune) Add two polynomials p1(x) and p2(x) given their coefficients, optionally pruning the results.static BezierPolynomial
add
(BezierPolynomial p1, BezierPolynomial p2) Add one bezier polynomial to another.static BezierPolynomial
add
(BezierPolynomial result, BezierPolynomial p1, BezierPolynomial p2) Add one Bézier polynomial to another, storing the results in an existing Bézier polynomial.static Polynomial
add
(Polynomial p1, Polynomial p2) Add one polynomial to another.static Polynomial
add
(Polynomial result, Polynomial p1, Polynomial p2) Add one polynomial to another, storing the results in an existing polynomial.static int
bezierAdd
(double[] result, double[] p1, int n1, double[] p2, int n2) Add two polynomials p1(x) and p2(x) represented using coefficients for a Bernstein basis.static int
bezierMultiply
(double[] result, double[] p1, int n1, double[] p2, int n2) Multiply two polynomials p1(x) and p2(x) given their coefficients.static int
divide
(double[] q, double[] r, double[] p1, int n1, double[] p2, int n2) Divide a polynomial p1(x) by a polynomial p2(x).static BezierPolynomial
divide
(BezierPolynomial p1, BezierPolynomial p2, boolean isQuotient) Divide one Bézier polynomial by another, returning either the quotient or the remainderstatic void
divide
(BezierPolynomial q, BezierPolynomial r, BezierPolynomial p1, BezierPolynomial p2) Divide one Bézier polynomial by another, computing both the quotient and the remainder.static Polynomial
divide
(Polynomial p1, Polynomial p2, boolean isQuotient) Divide one polynomial by another, returning either the quotient or the remainderstatic void
divide
(Polynomial q, Polynomial r, Polynomial p1, Polynomial p2) Divide one polynomial by another, computing both the quotient and the remainder.static Polynomial[]
Factor a quartic polynomial into two quadratic polynomials; The factors will consist of 1 to 3 polynomials.static Polynomial[]
Factor a reduced quartic polynomial.static double[]
fromBezier
(double[] result, double[] beta, int offset, int n) Convert from a Bernstein basis to a monomial basis, providing an array to store the monomial coefficients.static double[]
fromBezier
(double[] beta, int offset, int n) Convert from a Bernstein basis to a monomial basis.static int
getDegree
(double[] r, int n2) Get the degree of a polynomial.static double
Get the value set bysetRootP4Limit(double)
or its default value ifsetRootP4Limit(double)
has not been called.static double
Get the value set bysetRootP4SFLimit(double)
or its default value ifsetRootP4SFLimit(double)
has not been called.static RealValuedFunctOps
Integral of the square root of a quartic polynomial that has no real roots.static double
integrateAbsPRootQ
(double u, Polynomial p, Polynomial rp) Compute the integral of |p(x)|sqrt(rp(x)) where p and rp are polynomials with degrees 0, 1, or 2, and 0 or 2 respectively.static double
integrateRoot2Q
(int p1, int p2, int p5, Polynomial P1, Polynomial P2, Polynomial P5, double y, double x) Integrate an expression containing the square roots of two quadratic polynomials using elliptic integrals.static double
integrateRootP2
(double x, double a, double b, double c) Compute an indefinite integral of the square root of the polynomial a + bx + cx2.static double
integrateRootP4
(Polynomial p, double y, double x) Integrate the square root of a quartic polynomial that has no real roots.static double
integrateXRootP2
(double x, double a, double b, double c) Compute an indefinite integral of x times the square root of the polynomial a + bx + cx2.static int
multiply
(double[] result, double[] p1, int n1, double[] p2, int n2) Multiply two polynomials p1(x) and p2(x) given their coefficients.static int
multiply
(double[] result, double s, double[] p, int n) Multiple a polynomial p(x), given its coefficients, by a scalar s.static BezierPolynomial
multiply
(double s, BezierPolynomial p) Multiply a Bézier polynomial by a scalar.static Polynomial
multiply
(double s, Polynomial p) Multiply a polynomial by a scalar.static BezierPolynomial
multiply
(BezierPolynomial result, double s, BezierPolynomial p) Multiply a Bezierpolynomial by a scalar, storing the results in an existing polynomial.static BezierPolynomial
multiply
(BezierPolynomial p1, BezierPolynomial p2) Multiply one Bézier polynomial by another.static BezierPolynomial
multiply
(BezierPolynomial result, BezierPolynomial p1, BezierPolynomial p2) Multiply one Bézier polynomial by another, storing the results in an existing Bézier polynomial.static Polynomial
multiply
(Polynomial result, double s, Polynomial p) Multiply a polynomial by a scalar, storing the results in an existing polynomial.static Polynomial
multiply
(Polynomial p1, Polynomial p2) Multiply one polynomial by another.static Polynomial
multiply
(Polynomial result, Polynomial p1, Polynomial p2) Multiply one polynomial by another, storing the results in an existing polynomial.static void
setRootP4Limit
(double value) Set the limit for the minimum value for a factor of the polynomiial passed tointegrateRootP4(Polynomial,double,double)
.static void
setRootP4SFLimit
(double value) Set the limit for the minimum relative difference for the factors of the polynomiial passed tointegrateRootP4(Polynomial,double,double)
.static void
testRootP4
(boolean value) Test that factoring is accurate when integrateRootP4 is called.static double[]
toBezier
(double[] a, int n) Convert a monomial polynomial to one using a Bernstein basis with the same degree.static double[]
toBezier
(double[] beta, int offset, double[] a, int n) Convert a monomial polynomial to one using a Bernstein basis with the same degree, providing an output array.
-
Constructor Details
-
Polynomials
public Polynomials()
-
-
Method Details
-
toBezier
public static double[] toBezier(double[] a, int n) Convert a monomial polynomial to one using a Bernstein basis with the same degree. When this method exits, $$ \sum_{i=0}^n a_i x^i = \sum_{i=0}^n \beta_i B_{i,n}(x) \ .$$ .The length of the array a must be at least n+1.
- Parameters:
a
- the polynomial's coefficients using a monomial basis.n
- the degree of the polynomial- Returns:
- an array containing the polynomial's coefficients using a Bernstein basis.
- Throws:
NullPointerException
- an argument was nullIllegalArgumentException
- an array had the wrong size or the arguments offset or n had an incorrect value
-
toBezier
public static double[] toBezier(double[] beta, int offset, double[] a, int n) throws NullPointerException, IllegalArgumentException Convert a monomial polynomial to one using a Bernstein basis with the same degree, providing an output array. When this method exits, $$ \sum_{i=0}^n a_i x^i = \sum_{i=0}^n \beta_i B_{i,n}(x) \ .$$The length of the array a must be at least n+1 and the length of the array beta, if not null, must be at least offset + n + 1. if beta is null, the coefficients will start at the specified offset into the array beta, which will be allocated with a length of offset + n + 1.
- Parameters:
beta
- an array that will contain the coefficients using a Bernstein basis; null if a new array will be allocatedoffset
- the offset into the array for the 0th Bernstein coefficienta
- the polynomial's coefficients using a monomial basis.n
- the degree of the polynomial- Returns:
- the first argument; a new array that contains the coefficients using a Bernstein basis if the first argument is null
- Throws:
NullPointerException
- an argument was nullIllegalArgumentException
- an array had the wrong size or the arguments offset or n had an incorrect value
-
fromBezier
public static double[] fromBezier(double[] beta, int offset, int n) Convert from a Bernstein basis to a monomial basis. The conversion uses the relation $$\sum_{j=0}^n\beta_jB_{j,n}(t) = \sum_{i=0}^n\sum_{k=0}^i\beta_k(-1)^{i-k} \left(\begin{array}{c}n\\i\end{array}\right) \left(\begin{array}{c}i\\k\end{array}\right)t^i\ .$$- Parameters:
beta
- an array containing the coefficients using a Bernstein basisoffset
- the offset into the array for the 0th Bernstein coefficientn
- the degree of the polynomial- Returns:
- the coefficients for a monomial basis.
-
fromBezier
public static double[] fromBezier(double[] result, double[] beta, int offset, int n) throws NullPointerException, IllegalArgumentException Convert from a Bernstein basis to a monomial basis, providing an array to store the monomial coefficients. The conversion uses the relation $$\sum_{j=0}^n\beta_jB_{j,n}(t) = \sum_{i=0}^n\sum_{k=0}^i\beta_k(-1)^{i-k} \left(\begin{array}{c}n\\i\end{array}\right) \left(\begin{array}{c}i\\k\end{array}\right)t^i\ .$$- Parameters:
result
- an array that will contain the coefficients for a monomial basis (this array will be the value returned unless it is null, in which case an array will be allocated).beta
- an array containing the coefficients using a Bernstein basisoffset
- the offset into the array for the 0th Bernstein coefficientn
- the degree of the polynomial- Returns:
- the coefficients for a monomial basis.
- Throws:
NullPointerException
- the second argument was nullIllegalArgumentException
- the array sizes too small or the offset was out of range
-
multiply
Multiply one polynomial by another.- Parameters:
p1
- the first polynomialp2
- the second polynomial- Returns:
- the product of p1 and p2
- Throws:
NullPointerException
-
multiply
public static BezierPolynomial multiply(BezierPolynomial p1, BezierPolynomial p2) throws NullPointerException Multiply one Bézier polynomial by another.- Parameters:
p1
- the first polynomialp2
- the second polynomial- Returns:
- the product of p1 and p2
- Throws:
NullPointerException
-
multiply
public static Polynomial multiply(Polynomial result, Polynomial p1, Polynomial p2) throws NullPointerException Multiply one polynomial by another, storing the results in an existing polynomial.- Parameters:
result
- the polynomial holding the results; null if a new one should be allocatedp1
- the first polynomialp2
- the second polynomial- Returns:
- the product of p1 and p2 (i.e., the result argument)
- Throws:
NullPointerException
- the second argument was null
-
multiply
public static BezierPolynomial multiply(BezierPolynomial result, BezierPolynomial p1, BezierPolynomial p2) throws NullPointerException Multiply one Bézier polynomial by another, storing the results in an existing Bézier polynomial.- Parameters:
result
- the polynomial holding the results; null if a new one should be allocatedp1
- the first polynomialp2
- the second polynomial- Returns:
- the product of p1 and p2 (i.e., the result argument)
- Throws:
NullPointerException
- the second argument was null
-
multiply
public static int multiply(double[] result, double[] p1, int n1, double[] p2, int n2) throws IllegalArgumentException, NullPointerException Multiply two polynomials p1(x) and p2(x) given their coefficients. Coefficients are order so that, for a polynomial p(x) = a0 + a1x + ... + anxn, the coefficient for the xi term is stored in an array at index i, thus making a0 the first index in p's coefficient array. The any of the arrays result, p1, and p2 may be identical arrays (temporary copies will be made as needed).- Parameters:
result
- the coefficients for p1 multiply by p2 (the array size must be at least n1+n2+1)p1
- the coefficients for p1n1
- the degree of p1p2
- the coefficients for p2n2
- the degree of p2- Returns:
- the degree of the polynomial p1(x)p2(x)
- Throws:
NullPointerException
- the second argument was nullIllegalArgumentException
- an argument was out of range or an array was too short
-
bezierMultiply
public static int bezierMultiply(double[] result, double[] p1, int n1, double[] p2, int n2) throws IllegalArgumentException Multiply two polynomials p1(x) and p2(x) given their coefficients. Coefficients are order so that, for a polynomial p(x) = a0 + a1x + ... + anxn, the coefficient for the xi term is stored in an array at index i, thus making a0 the first index in p's coefficient array. The any of the arrays result, p1, and p2 may be identical arrays (temporary copies will be made as needed).- Parameters:
result
- the coefficients for p1 multiply by p2 (the array size must be at least n1+n2+1)p1
- the coefficients for p1n1
- the degree of p1p2
- the coefficients for p2n2
- the degree of p2- Returns:
- the degree of the polynomial p1(x)p2(x)
- Throws:
IllegalArgumentException
-
multiply
Multiply a polynomial by a scalar.- Parameters:
s
- the scalarp
- the polynomial- Returns:
- the product of s and p
- Throws:
NullPointerException
-
multiply
Multiply a Bézier polynomial by a scalar.- Parameters:
s
- the scalarp
- the polynomial- Returns:
- the product of s and p
- Throws:
NullPointerException
-
multiply
public static Polynomial multiply(Polynomial result, double s, Polynomial p) throws NullPointerException Multiply a polynomial by a scalar, storing the results in an existing polynomial.- Parameters:
result
- the polynomial holding the results; null if a new one should be allocateds
- the scalarp
- the polynomial- Returns:
- the product of s and p (i.e., the result argument)
- Throws:
NullPointerException
-
multiply
public static BezierPolynomial multiply(BezierPolynomial result, double s, BezierPolynomial p) throws NullPointerException Multiply a Bezierpolynomial by a scalar, storing the results in an existing polynomial.- Parameters:
result
- the polynomial holding the results; null if a new one should be allocateds
- the scalarp
- the polynomial- Returns:
- the product of s and p (i.e., the result argument)
- Throws:
NullPointerException
-
multiply
public static int multiply(double[] result, double s, double[] p, int n) Multiple a polynomial p(x), given its coefficients, by a scalar s. Coefficients are order so that, for a polynomial p(x) = a0 + a1x + ... + anxn, the coefficient for the xi term is stored in an array at index i, thus making a0 the first index in p's coefficient array.The arrays result and p may be identical.
- Parameters:
result
- the coefficients for p(x)s
- the scalarp
- the coefficients for pn
- the degree of the polynomial p(x)- Returns:
- the degree of p;
-
add
Add one polynomial to another.- Parameters:
p1
- the first polynomialp2
- the second polynomial- Returns:
- the sum of p1 and p2
- Throws:
NullPointerException
-
add
public static BezierPolynomial add(BezierPolynomial p1, BezierPolynomial p2) throws NullPointerException Add one bezier polynomial to another.- Parameters:
p1
- the first polynomialp2
- the second polynomial- Returns:
- the sum of p1 and p2
- Throws:
NullPointerException
-
add
public static Polynomial add(Polynomial result, Polynomial p1, Polynomial p2) throws NullPointerException Add one polynomial to another, storing the results in an existing polynomial.- Parameters:
result
- the polynomial holding the results; null if a new one should be allocatedp1
- the first polynomialp2
- the second polynomial- Returns:
- the sum of p1 and p2 (i.e., the result argument)
- Throws:
NullPointerException
- the second or third argument was null
-
add
public static BezierPolynomial add(BezierPolynomial result, BezierPolynomial p1, BezierPolynomial p2) throws NullPointerException Add one Bézier polynomial to another, storing the results in an existing Bézier polynomial.- Parameters:
result
- the polynomial holding the results; null if a new one should be allocatedp1
- the first polynomialp2
- the second polynomial- Returns:
- the sum of p1 and p2 (i.e., the result argument)
- Throws:
NullPointerException
- an argument was null
-
add
public static int add(double[] result, double[] p1, int n1, double[] p2, int n2) Add two polynomials p1(x) and p2(x) given their coefficients. Coefficients are order so that, for a polynomial p(x) = a0 + a1x + ... + anxn, the coefficient for the xi term is stored in an array at index i, thus making a0 the first index in p's coefficient array. The size of theresult
array must be at least max(n1+1, n2+1).- Parameters:
result
- an array of coefficients for the polynomial p1(x)+p2(x)p1
- the coefficients for p1n1
- the degree of p1p2
- the coefficients for p2n2
- the degree of p2- Returns:
- the degree of the polynomial p1(x)+p2(x)
-
add
public static int add(double[] result, double[] p1, int n1, double[] p2, int n2, boolean prune) throws NullPointerException Add two polynomials p1(x) and p2(x) given their coefficients, optionally pruning the results. Coefficients are order so that, for a polynomial p(x) = a0 + a1x + ... + anxn, the coefficient for the xi term is stored in an array at index i, thus making a0 the first index in p's coefficient array. The size of theresult
array must be at least max(n1+1, n2+1).The polynomial may be optionally pruned: when the final coefficients are zero, those are eliminated from the polynomial by decreasing the degree that is returned.
- Parameters:
result
- an array of coefficients for the polynomial p1(x)+p2(x)p1
- the coefficients for p1n1
- the degree of p1p2
- the coefficients for p2n2
- the degree of p2prune
- true if the result should be pruned; false otherwise- Returns:
- the degree of the polynomial p1(x)+p2(x)
- Throws:
NullPointerException
- an argument was null
-
bezierAdd
public static int bezierAdd(double[] result, double[] p1, int n1, double[] p2, int n2) throws NullPointerException Add two polynomials p1(x) and p2(x) represented using coefficients for a Bernstein basis. The size of theresult
array must be at least max(n1+1, n2+1), and the basis used will be one appropriate for the degree returned.- Parameters:
result
- an array of coefficients for the polynomial p1(x)+p2(x)p1
- the coefficients for p1n1
- the degree of p1p2
- the coefficients for p2n2
- the degree of p2- Returns:
- the degree of the polynomial p1(x)+p2(x)
- Throws:
NullPointerException
- an argument was null
-
divide
public static Polynomial divide(Polynomial p1, Polynomial p2, boolean isQuotient) throws NullPointerException Divide one polynomial by another, returning either the quotient or the remainderPlease see
divide(double[],double[],double[],int,double[],int)
for documentation regarding numerical accuracy.- Parameters:
p1
- the first polynomial (the dividend)p2
- the second polynomial (the divisor)isQuotient
- true if the polynomial returned is a quotient; false if it is a remainder- Returns:
- the quotient or the remainder of p1 divided by p2
- Throws:
NullPointerException
- an argument was null
-
divide
public static BezierPolynomial divide(BezierPolynomial p1, BezierPolynomial p2, boolean isQuotient) throws NullPointerException Divide one Bézier polynomial by another, returning either the quotient or the remainderPlease see
divide(double[],double[],double[],int,double[],int)
for documentation regarding numerical accuracy (this method is used by the implementation of this operation for instances of BezierPolynomial).- Parameters:
p1
- the first polynomial (the dividend)p2
- the second polynomial (the divisor)isQuotient
- true if the polynomial returned is a quotient; false if it is a remainder- Returns:
- the quotient or the remainder of p1 divided by p2
- Throws:
NullPointerException
- an argument was null
-
divide
public static void divide(Polynomial q, Polynomial r, Polynomial p1, Polynomial p2) throws NullPointerException Divide one polynomial by another, computing both the quotient and the remainder.Please see
divide(double[],double[],double[],int,double[],int)
for documentation regarding numerical accuracy.- Parameters:
q
- a polynomial used to store the quotient; null if the quotient is not wantedr
- the polynomial used to store the remainder; null if the remainder is not wantedp1
- the first polynomial (the dividend)p2
- the second polynomial (the divisor)- Throws:
NullPointerException
- the third or fourth argument was null
-
divide
public static void divide(BezierPolynomial q, BezierPolynomial r, BezierPolynomial p1, BezierPolynomial p2) throws NullPointerException Divide one Bézier polynomial by another, computing both the quotient and the remainder. Please seedivide(double[],double[],double[],int,double[],int)
for documentation regarding numerical accuracy (this method is used by the implementation of this operation for instances of BezierPolynomial).- Parameters:
q
- a polynomial used to store the quotient; null if the quotient is not wantedr
- the polynomial used to store the remainder; null if the remainder is not wantedp1
- the first polynomial (the dividend)p2
- the second polynomial (the divisor)- Throws:
NullPointerException
- an argument was null
-
divide
public static int divide(double[] q, double[] r, double[] p1, int n1, double[] p2, int n2) throws IllegalArgumentException, NullPointerException Divide a polynomial p1(x) by a polynomial p2(x). The results are polynomials q(x) and r(x) such that p1(x) = q(x)p2(x) + r(x), with the degree of r(x) less than the degree of px(x). Coefficients are order so that, for a polynomial p(x) = a0 + a1x + ... + anxn, the coefficient for the xi term is stored in an array at index i, thus making a0 the first index in p's coefficient array. Any of the arrays q, r, p1, and p2 may be identical arrays except that q ≠ p (temporary copies will be made as needed). The length of q must be non-negative and at least (n1 - n2 + 1), and the length of r must be at least n1+1.The arrays that are returned should be checked to determine numerical stability of any computation. For example, the following code
will produce the following values for q and r:int deg1 = 10; int deg2 = 1; double[] p1 = new double[deg1+1]; double[] p2 = new double[deg2+1]; p1[0] = 5.055832194989883; p1[1] = -6.377532529195433; p1[2] = -1.648066454379407; p1[3] = -6.664776987879824; p1[4] = -9.913142660200338; p1[5] = 11.011644731787342; p1[6] = 6.499930124981663; p1[7] = 16.59232841567509; p1[8] = -16.11922415992573; p1[9] = 19.852145288267316; p1[10] = -4.9061808702028245; p2[0] = -14.267558704211917; p2[1] = -0.16512094757360885; double[] q = new double[20]; double[] r = new double[20]; double[] result = new double[20]; int nq = Polynomials.divide(q, r, p1, deg1, p2, deg2); int nr = Polynomials.getDegree(r, deg1);
Due to a range of 20 orders of magnitude, the value for the coefficients for p1 and for the product qp2+r will differ by amounts that may be comparable to p1's coefficients.... q[0] = -8.3546709168710031E18 ... q[1] = 9.6690064997045424E16 ... q[2] = -1.1190110014092871E15 ... q[3] = 1.2950509665220766E13 ... q[4] = -1.498785091272303E11 ... q[5] = 1.7345701496704223E9 ... q[6] = -2.0074483601869095E7 ... q[7] = 232324.34018894564 ... q[8] = -2687.600364379947 ... q[9] = 29.71264968071789 ... r[0] = -1.1920075776082903E20
- Parameters:
q
- the coefficients for the quotient polynomial q(x)r
- the coefficients for the remainder polynomial r(x)p1
- the coefficients for p1n1
- the degree of p1p2
- the coefficients for p2n2
- the degree of p2- Returns:
- the degree of the polynomial q(x)
- Throws:
NullPointerException
- an argument was nullIllegalArgumentException
- if the array provided by the first or second argument was too short or if the first two arguments are the same array
-
getDegree
Get the degree of a polynomial. One use of this method is to find the degree of the remainder after Euclidean division. In that case, the argument n2 should be the degree of the dividend, but may be the degree of the divisor if that is smaller than the degree of the dividend.- Parameters:
r
- the array containing the remainder's coefficientsn2
- the largest index in r that might have been set- Returns:
- the degree of the polynomial r(x)
- Throws:
NullPointerException
- an argument was null
-
factorReducedQuartic
public static Polynomial[] factorReducedQuartic(Polynomial p) throws IllegalArgumentException, NullPointerException, ArithmeticException Factor a reduced quartic polynomial. The polynomial must be x4 + cx2 + dx + e for some choice of c, d, and e. The algorithm is described in G. Brookfield, " Factoring Quartic Polynomials: A Lost Art", Mathematics Magazine, Vol. 80, No. 1, February 2007, Pages 67–70. This article actually describes factoring polynomials with the constraint that the original polynomial and its factors have only rational coefficients, i.e., in the field Q. The proofs, however are dependent only on Q being a field, and work the same if Q is replaced with the field of real numbers R.Note: The documentation for the method
Polynomial.reducedFormShift()
indicates how to generate the reduced form for a polynomial. After factoring, the factors can be shifted back to recover factors for the original polynomial. A reduced quartic polynomial must have its x3 term set to 0.0 and its x4term set to 1.0. with no roundoff errors.- Parameters:
p
- the polynomial to factor- Returns:
- an array of polynomials containing two factors;
- Throws:
NullPointerException
- the argument was nullIllegalArgumentException
- the argument was not a reduced quartic polynomialArithmeticException
- if factorization failed, probably because of a round-off error- See Also:
-
factorQuarticToQuadratics
public static Polynomial[] factorQuarticToQuadratics(Polynomial p) throws IllegalArgumentException, NullPointerException, ArithmeticException Factor a quartic polynomial into two quadratic polynomials; The factors will consist of 1 to 3 polynomials. The first, at index 0 in the returned array, is a 0th degree polynomial whose value is a scale factor. This is followed by one or two polynomials. If one, the polynomial at index 1 will be the original polynomial scaled so that its x4 argument is 1.0. If two, the polynomial at index 1 and 2 will be quadratic polynomials representing two quadratic factors.- Parameters:
p
- the polynomial- Returns:
- the factors; null if factorization failed
- Throws:
NullPointerException
- an argument was nullIllegalArgumentException
- if the polynomial is not a quartic polynomialArithmeticException
- if factorization failed, probably because of a round-off error
-
integrateAbsPRootQ
public static double integrateAbsPRootQ(double u, Polynomial p, Polynomial rp) throws IllegalArgumentException, ArithmeticException Compute the integral of |p(x)|sqrt(rp(x)) where p and rp are polynomials with degrees 0, 1, or 2, and 0 or 2 respectively. If p has a degree of 2, rp must have a degree of 0.- Parameters:
u
- the upper limit of integrationp
- A 0, 1st, or 2nd degree polynomialrp
- A 0 or 2nd degree polynomial- Throws:
IllegalArgumentException
ArithmeticException
-
setRootP4Limit
public static void setRootP4Limit(double value) Set the limit for the minimum value for a factor of the polynomiial passed tointegrateRootP4(Polynomial,double,double)
. The polynomial, if factoring is successful, will have three values: a 0 degree polynomial (a scalar), and two second-degree polynomals whose x2 term is 1.0. Both factors must be polynomials with positive values for all values of their arguments. When the minimum is too close to zero compared to the maximum of the absolute value of the polynomial's coefficients, an exeception will be thrown as an indication that the results are not reliable.To turn off this test, set the limit to 0.0. The default value is 1.e-4.
- Parameters:
value
- the value for the limit
-
getRootP4Limit
public static double getRootP4Limit()Get the value set bysetRootP4Limit(double)
or its default value ifsetRootP4Limit(double)
has not been called.- Returns:
- the value
- See Also:
-
testRootP4
public static void testRootP4(boolean value) Test that factoring is accurate when integrateRootP4 is called.- Parameters:
value
- true if factoring should be tested; false otherwise.
-
setRootP4SFLimit
public static void setRootP4SFLimit(double value) Set the limit for the minimum relative difference for the factors of the polynomiial passed tointegrateRootP4(Polynomial,double,double)
. The polynomial, if factoring is successful, will have three values: a 0 degree polynomial (a scalar), and two second-degree polynomals whose x2 term is 1.0. Both factors must be polynomials with positive values for all values of their arguments. If the two second-degree polynomials are equal, the integral reduces to that for the absolute value of a quadratic polynomial. If they differ by a small amount, an approximation based on a Taylor series expansion is used (keeping the first order terms in the expansion is equivalent to averaging the two quadratics).The default value for the limit is 1.e-7.
- Parameters:
value
- the value for the limit
-
getRootP4SFLimit
public static double getRootP4SFLimit()Get the value set bysetRootP4SFLimit(double)
or its default value ifsetRootP4SFLimit(double)
has not been called.- Returns:
- the value
- See Also:
-
integrateRootP4
public static double integrateRootP4(Polynomial p, double y, double x) throws IllegalArgumentException, ArithmeticException Integrate the square root of a quartic polynomial that has no real roots. The value of the polynomial must be positive for all values of its argument.Note: this method can be used in computing the length of a cubic Bézier curve.
- Parameters:
p
- the polynomial whose square root is to be integratedy
- the lower limit of integrationx
- the upper limit of integration- Throws:
NullPointerException
- an argument was nullIllegalArgumentException
- if the polynomial is not a quartic polynomialArithmeticException
- if factorization failed, probably because of a round-off error, or if the factors are not positive for all values of their arguments
-
integralOfRootP4
public static RealValuedFunctOps integralOfRootP4(Polynomial p) throws IllegalArgumentException, ArithmeticException Integral of the square root of a quartic polynomial that has no real roots. The value of the polynomial must be positive for all values of its argument.Note: this method can be used in computing the length of a cubic Bézier curve up to intermediate values of the path parameter. When used multiple times, it is faster than
integrateRootP4(Polynomial,double,double)
because the polynomial is factored only once.- Parameters:
p
- the polynomial whose square root is to be integrated- Throws:
NullPointerException
- an argument was nullIllegalArgumentException
- if the polynomial is not a quartic polynomialArithmeticException
- if factorization failed, probably because of a round-off error, or if the factors are not positive for all values of their arguments
-
integrateRoot2Q
public static double integrateRoot2Q(int p1, int p2, int p5, Polynomial P1, Polynomial P2, Polynomial P5, double y, double x) throws NullPointerException, IllegalArgumentException Integrate an expression containing the square roots of two quadratic polynomials using elliptic integrals. The integral is $$ \int_y^x A(t)^{p_1/2}B(t)^{p_2/2}(a_5+b_5t)^{p_3/2} dt \ .$$ where A(t) = f1 +g1t + h1t2 and B(t) = f2 +g2t + h2t2 are quadratic polynomials whose values are positive for all t, and where p₁ and p₂ are odd integers and p₅ is an even integer. These integers must have the specific values given in the following table:p₁ p₂ p₅ -1 -1 0 -3 1 0 -3 -1 0 -1 -1 -2 1 -1 -4 -1 -1 -4 -1 -1 2 1 -1 0 -1 -1 4 1 1 0 1 -1 -2 1 1 -2 1 1 -4 The caller must ensure that neither quadratic polynomials has a real root and that they are different polynomials.
See B. C. Carlson, " A Table of Elliptic Integrals: Two Quadratic Factors", Mathematics of Computation, Volume 59, Number 199, July 1992, Pages 165–180 for further details and the algorithm used. The notation for this method is based on this paper. While Carlson's paper requires that x > y, this implementation does not have that restriction.
- Parameters:
p1
- the value of p1 as provided in the previous tablep2
- the value of p2 as provided in the previous tablep5
- the value of p3 as provided in the previous tableP1
- the polynomial A(t) described aboveP2
- the polynomial B(t) described aboveP5
- the polynomial a5 + b5t; null if p5 is zeroy
- the lower limit of integrationx
- the upper limit of integration- Returns:
- the value of the integral from y to x
- Throws:
NullPointerException
- an argument was nullIllegalArgumentException
- if an argument is out of range
integrateRootP2
public static double integrateRootP2(double x, double a, double b, double c) throws ArithmeticException Compute an indefinite integral of the square root of the polynomial a + bx + cx2. The polynomial must have a non-negative value at x=0 and at the upper limit of integration. For convenience, the integral will have a value of 0 when x=0.- Parameters:
x
- the upper limit of integrationa
- the zeroth order coefficient of a polynomialb
- the first order coefficient of a polynomialc
- the second order coefficient of a polynomial- Returns:
- the value of the integral
- Throws:
ArithmeticException
- if the integral cannot be computed
integrateXRootP2
public static double integrateXRootP2(double x, double a, double b, double c) throws ArithmeticException Compute an indefinite integral of x times the square root of the polynomial a + bx + cx2. The polynomial must have a non-negative value at x=0 and at the upper limit of integration.- Parameters:
x
- the upper limit of integrationa
- the zeroth order coefficient of a polynomialb
- the first order coefficient of a polynomialc
- the second order coefficient of a polynomial- Returns:
- the value of the integral
- Throws:
ArithmeticException
- if the integral cannot be computed
-