- Enclosing class:
- Functions
-
Method Summary
Modifier and TypeMethodDescriptionstatic BezierPolynomial
asBezierPolynomial
(int n) Create a Legendre polynomial of degree n using a Bernstein basis.static Polynomial
asPolynomial
(int n) Create a Legendre polynomial of degree n using a monomial basis.static double
derivative
(int n, int m, double x, double[] results) Compute the derivative of an associated Legendre function of degree n and order mstatic final int
roots
(int n, double[] r) Compute the roots of a Legendre polynomial of order n A heuristic algorithm is used to estimate the iteration limit (the number of iterations before the accuracy is relaxed).static final int
roots
(int n, double[] r, int iterationLimit) Compute the roots of a Legendre polynomial of order n with a specified iteration limit.static final int
roots
(int n, double[] r, int iterationLimit, double accuracy) Compute the roots of a Legendre polynomial of order n with a specified accuracy and iteration limit.static double
valueAt
(int n, double x) Evaluate a Legendre polynomial.static double
valueAt
(int n, int m, double x) Compute associated Legendre functions with integer coefficients.static double
valueUpTo
(int n, double x, double[] results) Evaluate Legendre polynomials for multiple orders.
-
Method Details
-
valueAt
public static double valueAt(int n, double x) Evaluate a Legendre polynomial.- Parameters:
n
- the order of the Legendre polynomialx
- the point at which the polynomial should be evaluated- Returns:
- the value of the polynomial
-
valueUpTo
public static double valueUpTo(int n, double x, double[] results) Evaluate Legendre polynomials for multiple orders.- Parameters:
n
- the maximum order or degree of the polynomialx
- the point at which the polynomial is to be evaluatedresults
- an array of at least size n+1 to hold values for orders 0 to n- Returns:
- the value for order n at point x
-
valueAt
Compute associated Legendre functions with integer coefficients.Implementation note: Using Rodrigues' formula yields Pnm(x) = (-1)m(1-x2)m/2 (dn+m/dxn+m)(x2-1)n. The term (x2-1)n can be expanded using the binomial theorem to a sum over i of terms that are equal to C(n,i)(-1)ix2(n-i). If we differentiate n+m times, the only nonzero values are for i less than or equal to the smallest integer such that 2(n-i) is larger than or equal to n+m: i.e., i goes from 0 to the largest integer no larger than (n-m)/2. For the ith term, let k = n-2i. After differentiation, the ith term will contain a factor of xk-m. In addition to the (-1)i factor and the C(n,i) factor, differentiating x2(n-i) n+m times yields a factor of (2(n-i))!/(2(n-i)-(n+m))!, which is equal to (2(n-i))!/(n-m-2i)! and which in turn is equal to C(2(n-1),n)C(k,m)n!m! with the n! conveniently canceling a factor of 1/n! in Rodrigues' formula.
- Parameters:
n
- the degreem
- the orderx
- the argument- Returns:
- the value of Pmn(x)
- Throws:
IllegalArgumentException
- an argument is out of range.
-
derivative
public static double derivative(int n, int m, double x, double[] results) throws IllegalArgumentException Compute the derivative of an associated Legendre function of degree n and order m- Parameters:
n
- the degree of the associated Legendre functionm
- the order of the associated Legendre functionx
- the point at which the polynomial is evaluatedresults
- an array of size 2 holding the values of the Legendre function at x for degree n and order m at index 0 and its derivative at index 1- Returns:
- the derivative at point x
- Throws:
IllegalArgumentException
-
roots
public static final int roots(int n, double[] r) Compute the roots of a Legendre polynomial of order n A heuristic algorithm is used to estimate the iteration limit (the number of iterations before the accuracy is relaxed). The default accuracy requires a root to differ from 0 by 1 part in 1.0E15, but may be relaxed if the method is not converging on a root in a given number of iterations.- Parameters:
n
- the order of the polynomialr
- an array of size n holding the roots of the polynomial- Returns:
- the number of roots
-
roots
public static final int roots(int n, double[] r, int iterationLimit) Compute the roots of a Legendre polynomial of order n with a specified iteration limit. This method provides more fine-grained control regarding an accuracy versus computing time trade-off.- Parameters:
n
- the order of the polynomialr
- an array of size n holding the roots of the polynomialiterationLimit
- the number of iterations before relaxing the accuracy of the computation- Returns:
- the number of roots
-
roots
public static final int roots(int n, double[] r, int iterationLimit, double accuracy) Compute the roots of a Legendre polynomial of order n with a specified accuracy and iteration limit. This method provides more fine-grained control regarding an accuracy versus computing time trade-off.- Parameters:
n
- the order of the polynomialr
- an array of size n holding the roots of the polynomialiterationLimit
- the number of iterations before relaxing the accuracy of the computationaccuracy
- the accuracy for convergence. If the value at a possible root exceeds the accuracy, iteration continues, but if the iteration limit is passed, the accuracy value is increased by a factor of 10.- Returns:
- the number of roots
-
asPolynomial
Create a Legendre polynomial of degree n using a monomial basis.- Parameters:
n
- the degree of the Legendre polynomial- Returns:
- the polynomial
- Throws:
IllegalArgumentException
- if the argument was negative
-
asBezierPolynomial
Create a Legendre polynomial of degree n using a Bernstein basis.- Parameters:
n
- the degree of the Legendre polynomial- Returns:
- the polynomial
- Throws:
IllegalArgumentException
- the argument was negative
-