com.tensegrity.generic.math
Class Polynomial

java.lang.Object
  extended bycom.tensegrity.generic.math.Polynomial

public final class Polynomial
extends java.lang.Object

The Polynomial class provides the functionality for multiplying and dividing polynomials with polynomials and monomials. Polynomials and their derivatives can be evaluated at arbitrary points and, most of all, they can be solved. Note that for quadratic polynomials, there is a specialized and extra stable method in class MathUtil, which is more appropriate for solving quadratic polynomials than using the method from the Polynomial class, which works for arbitrary degree polynomials.

This class represents a polynomial of degree n. Coefficient[i] corresponds to the x^i factor.

Version:
$Id: Polynomial.java,v 1.15 2006/01/26 17:05:22 MichaelKegel Exp $
Author:
S. Rutz

Constructor Summary
Polynomial(double[] coefficients)
          Builds a polynomial from the specified coefficients.
Polynomial(Polynomial polynomial)
          Copy constructor.
 
Method Summary
 void addPolynomial(Polynomial polynomial)
          Add with another polynomial.
 void divideMonomial(double a)
          Divide by a monomial (x - a).
 boolean equals(Polynomial polynomial, double accuracy)
          Checks whether this polynomial is equal to another polygon within the given accuracy for each coefficient.
 double eval(double x)
          Evaluate the value of the polynomial at point x.
 double evalDerivative(double x)
          Evaluate the derivative of the polynomial at point x.
 double get(int n)
          Returns the coefficient n of the polynomial
 int getDegree()
          Returns the degree of the polynomial
 void multiplyMonomial(double a)
          Multiply with a monomial (x - a).
 void multiplyPolynomial(Polynomial polynomial)
          Multiply with another polynomial.
 ArrayListDouble solve(double left, double right, double accuracy)
          Finds all real roots of the polynomial.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Polynomial

public Polynomial(double[] coefficients)
Builds a polynomial from the specified coefficients.

Parameters:
coefficients - array of coefficients that defines the polynomial. coefficient[i] corresponds to the x^i factor.

Polynomial

public Polynomial(Polynomial polynomial)
Copy constructor.

Parameters:
polynomial - the source polynomial to copy from.
Method Detail

getDegree

public final int getDegree()
Returns the degree of the polynomial

Returns:
degree of the polynomial

get

public final double get(int n)
Returns the coefficient n of the polynomial

Parameters:
n - the index of the coefficient.
Returns:
the coefficient at index n.

equals

public final boolean equals(Polynomial polynomial,
                            double accuracy)
Checks whether this polynomial is equal to another polygon within the given accuracy for each coefficient.

Parameters:
polynomial - the Polynomial to check.
accuracy - the accuracy of the comparison
Returns:
true if the polynomials are equal.

eval

public final double eval(double x)
Evaluate the value of the polynomial at point x.

Parameters:
x - the x value to evaluate the polynomial for.
Returns:
f(x) at x.

evalDerivative

public final double evalDerivative(double x)
Evaluate the derivative of the polynomial at point x.

Parameters:
x - the x value to evaluate the polynomial for.
Returns:
f'(x) at x.

multiplyPolynomial

public final void multiplyPolynomial(Polynomial polynomial)
Multiply with another polynomial. (this = this * p)

Parameters:
polynomial - the multiplier polynomial.

addPolynomial

public final void addPolynomial(Polynomial polynomial)
Add with another polynomial. (this = this * p)

Parameters:
polynomial - the polynomial to add.

multiplyMonomial

public final void multiplyMonomial(double a)
Multiply with a monomial (x - a).

Parameters:
a - the addend a of the monomial.

divideMonomial

public final void divideMonomial(double a)
Divide by a monomial (x - a).

Parameters:
a - the addend a of the monomial.

solve

public final ArrayListDouble solve(double left,
                                   double right,
                                   double accuracy)
Finds all real roots of the polynomial. The roots are numerically approximated until they are within the specified xacc interval.

Parameters:
left - left border of the interval to scan for solutions of the polynomial.
right - right border of the interval to scan for solutions of the polynomial.
accuracy - accuracy in x for the found solutions
Returns:
the solutions wrapped up in an arraylist.

toString

public java.lang.String toString()
Returns a string representation of this object.

Returns:
a string representation of this object.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.