org.jscience.mathematics.analysis.polynomials
Class DoublePolynomial

java.lang.Object
  extended by org.jscience.mathematics.analysis.DoubleFunction
      extended by org.jscience.mathematics.analysis.polynomials.DoublePolynomial
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Field.Member, Ring.Member, AbelianGroup.Member, AbstractMapping, C1Function, Polynomial, PrimitiveMapping, Member

public class DoublePolynomial
extends DoubleFunction
implements Polynomial, java.io.Serializable, java.lang.Cloneable

A Polynomial as a Ring.Member over a realField

See Also:
Serialized Form

Field Summary
static DoublePolynomial ONE
          The real polynomial representing the multiplicative identity.
static DoublePolynomial ZERO
          The real polynomial representing the additive identity.
 
Constructor Summary
DoublePolynomial(double[] coeff)
          Creates a new instance of DoublePolynomial, polynom is always simplified discarding every trailing zeros and array copied.
DoublePolynomial(double d, int degree)
          Simple constructor.
DoublePolynomial(DoublePolynomial polynomial)
          Creates a new instance of DoublePolynomial, polynom is always simplified discarding every trailing zeros.
DoublePolynomial(Field.Member[] f)
          Creates a new RealPolynomial object, polynom is always simplified discarding every trailing zeros and array copied.
 
Method Summary
 DoubleFunction add(DoubleFunction g)
          The group composition law.
 java.lang.Object clone()
           
static Complex[] cubic(double d, double c, double b, double a)
           
 int degree()
          The degree understood as the highest degree
 DoubleFunction differentiate()
          Differentiate the real polynomial.
 boolean equals(java.lang.Object o)
          Is this-o == Null ?
 DoublePolynomial[] euclidianDivision(DoublePolynomial divisor)
          Perform the euclidian division of two polynomials.
 Field.Member getCoefficient(int n)
          Get the coefficient of degree k, i.e.
 double getCoefficientAsDouble(int n)
          Get the coefficient of degree k, i.e.
 Field.Member[] getCoefficients()
          Get the coefficients as an array
 double[] getCoefficientsAsDoubles()
          Get the coefficients as an array of doubles
 java.lang.Object getSet()
           
 int hashCode()
          Some kind of hashcode...
 DoublePolynomial integrate()
          "inverse" operation for differentiate, zero degree constant set to zero
 boolean isOne()
          Returns true if this polynomial is equal to one.
 boolean isZero()
          Returns true if this polynomial is equal to zero.
 double map(double x)
          Evaluates this polynomial.
 double map(float x)
          Evaluates this polynomial.
 double map(int x)
          Evaluates this polynomial.
 double map(long x)
          Evaluates this polynomial.
 DoubleFunction multiply(DoubleFunction r)
          The multiplication law.
 AbelianGroup.Member negate()
          Returns the inverse member.
static Complex[] quadratic(double c, double b, double a)
           
 Complex[] roots()
           
static DoublePolynomial rootsToPolynomial(double[] roots)
           
 DoublePolynomial scalarDivide(double a)
          return a new real Polynomial with coefficients divided by a
 Polynomial scalarDivide(Field.Member f)
          return a new real Polynomial with coefficients divided by f
 DoublePolynomial scalarMultiply(double a)
          Returns the multiplication of this polynomial by a scalar
 Polynomial scalarMultiply(Field.Member f)
          Returns the multiplication of this polynomial by a scalar
 void setCoefficient(int n, Field.Member c)
          DOCUMENT ME!
 void setCoefficientAsDouble(int n, double c)
          DOCUMENT ME!
 DoubleFunction subtract(DoubleFunction g)
          The group composition law with inverse.
 ComplexPolynomial toComplexPolynomial()
           
 ExactComplexPolynomial toExactComplexPolynomial()
           
 ExactRealPolynomial toExactRealPolynomial()
           
 java.lang.String toString()
          String representation P(x) = a_k x^k +...
 java.lang.String toString(java.lang.String unknown)
          String representation P(x) = a_k x^k +...
 
Methods inherited from class org.jscience.mathematics.analysis.DoubleFunction
add, compose, cos, divide, divide, exp, getIntervalsList, inverse, log, multiply, power, setIntervalsList, sin, sqrt, subtract, taylorExpand, tensor
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.fields.Ring.Member
multiply
 
Methods inherited from interface org.jscience.mathematics.algebraic.groups.AbelianGroup.Member
add, subtract
 

Field Detail

ZERO

public static final DoublePolynomial ZERO
The real polynomial representing the additive identity.


ONE

public static final DoublePolynomial ONE
The real polynomial representing the multiplicative identity.

Constructor Detail

DoublePolynomial

public DoublePolynomial(double[] coeff)
Creates a new instance of DoublePolynomial, polynom is always simplified discarding every trailing zeros and array copied.

Parameters:
coeff - DOCUMENT ME!
Throws:
java.lang.NullPointerException - DOCUMENT ME!

DoublePolynomial

public DoublePolynomial(DoublePolynomial polynomial)
Creates a new instance of DoublePolynomial, polynom is always simplified discarding every trailing zeros.

Parameters:
polynomial - DOCUMENT ME!

DoublePolynomial

public DoublePolynomial(Field.Member[] f)
Creates a new RealPolynomial object, polynom is always simplified discarding every trailing zeros and array copied.

Parameters:
f -

DoublePolynomial

public DoublePolynomial(double d,
                        int degree)
Simple constructor. Build a one term polynomial from one coefficient and the corresponding degree.

Parameters:
d - coefficient
degree - degree associated with the coefficient
Method Detail

getCoefficient

public Field.Member getCoefficient(int n)
Get the coefficient of degree k, i.e. a_k if P(x) := sum_{k=0}^n a_k x^k

Specified by:
getCoefficient in interface Polynomial
Parameters:
n - degree
Returns:
coefficient as described above

getCoefficientAsDouble

public double getCoefficientAsDouble(int n)
Get the coefficient of degree k, i.e. a_k if P(x) := sum_{k=0}^n a_k x^k as a real number

Parameters:
n - degree
Returns:
coefficient as described above

getCoefficients

public Field.Member[] getCoefficients()
Get the coefficients as an array

Specified by:
getCoefficients in interface Polynomial
Returns:
the coefficients as an array

getCoefficientsAsDoubles

public double[] getCoefficientsAsDoubles()
Get the coefficients as an array of doubles

Returns:
the coefficients as an array

setCoefficient

public void setCoefficient(int n,
                           Field.Member c)
DOCUMENT ME!

Parameters:
n -

setCoefficientAsDouble

public void setCoefficientAsDouble(int n,
                                   double c)
DOCUMENT ME!

Parameters:
n -

map

public double map(double x)
Evaluates this polynomial.

Specified by:
map in interface PrimitiveMapping
Specified by:
map in class DoubleFunction
Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!
See Also:
org.jscience.mathematics.analysis.IntervalList.

map

public double map(float x)
Evaluates this polynomial.

Specified by:
map in interface PrimitiveMapping
Overrides:
map in class DoubleFunction
Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!

map

public double map(long x)
Evaluates this polynomial.

Specified by:
map in interface PrimitiveMapping
Overrides:
map in class DoubleFunction
Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!

map

public double map(int x)
Evaluates this polynomial.

Specified by:
map in interface PrimitiveMapping
Overrides:
map in class DoubleFunction
Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!

degree

public int degree()
The degree understood as the highest degree

Specified by:
degree in interface Polynomial
Returns:
the degree

getSet

public java.lang.Object getSet()

isZero

public boolean isZero()
Returns true if this polynomial is equal to zero. All coefficients are tested for |a_k| < GlobalSettings.ZERO_TOL.

Returns:
true if all coefficients < GlobalSettings.ZERO_TOL

isOne

public boolean isOne()
Returns true if this polynomial is equal to one. It is tested, whether |a_0 - 1| <= GlobalSettings.ZERO_TOL and the remaining coefficients are |a_k| < GlobalSettings.ZERO_TOL.

Returns:
true if this is equal to one.

add

public DoubleFunction add(DoubleFunction g)
The group composition law. Returns a new polynom with grade = max( this.degree, g.degree)

Overrides:
add in class DoubleFunction
Parameters:
g - a group member
Returns:
DOCUMENT ME!

differentiate

public DoubleFunction differentiate()
Differentiate the real polynomial. Only useful iff the polynomial is built over a banach space and an appropriate multiplication law is provided.

Specified by:
differentiate in interface C1Function
Specified by:
differentiate in class DoubleFunction
Returns:
a new polynomial with degree = max(this.degree-1 , 0)

scalarDivide

public Polynomial scalarDivide(Field.Member f)
return a new real Polynomial with coefficients divided by f

Specified by:
scalarDivide in interface Polynomial
Parameters:
f - divisor
Returns:
new Polynomial with coefficients /= f
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

scalarDivide

public DoublePolynomial scalarDivide(double a)
return a new real Polynomial with coefficients divided by a

Parameters:
a - divisor
Returns:
new Polynomial with coefficients /= a

equals

public boolean equals(java.lang.Object o)
Is this-o == Null ?

Overrides:
equals in class java.lang.Object
Parameters:
o - the other polynomial
Returns:
true if so

hashCode

public int hashCode()
Some kind of hashcode... (Since I have an equals)

Overrides:
hashCode in class java.lang.Object
Returns:
a hashcode

integrate

public DoublePolynomial integrate()
"inverse" operation for differentiate, zero degree constant set to zero

Returns:
the integrated polynomial

scalarMultiply

public Polynomial scalarMultiply(Field.Member f)
Returns the multiplication of this polynomial by a scalar

Specified by:
scalarMultiply in interface Polynomial
Parameters:
f -
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

scalarMultiply

public DoublePolynomial scalarMultiply(double a)
Returns the multiplication of this polynomial by a scalar

Parameters:
a - factor
Returns:
new Polynomial with coefficients = a

multiply

public DoubleFunction multiply(DoubleFunction r)
The multiplication law. Multiplies this Polynomial with another

Overrides:
multiply in class DoubleFunction
Parameters:
r - a RealFunction
Returns:
a new Polynomial with grade = max( this.grade, r.grade) + min( this.grade, r.grade) -1
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

negate

public AbelianGroup.Member negate()
Returns the inverse member. (That is mult(-1))

Specified by:
negate in interface AbelianGroup.Member
Overrides:
negate in class DoubleFunction
Returns:
inverse

subtract

public DoubleFunction subtract(DoubleFunction g)
The group composition law with inverse.

Overrides:
subtract in class DoubleFunction
Parameters:
g - a group member
Returns:
DOCUMENT ME!

toString

public java.lang.String toString()
String representation P(x) = a_k x^k +...

Overrides:
toString in class java.lang.Object
Returns:
String

toString

public java.lang.String toString(java.lang.String unknown)
String representation P(x) = a_k x^k +...

Parameters:
unknown - The name of the unkwown
Returns:
String

euclidianDivision

public DoublePolynomial[] euclidianDivision(DoublePolynomial divisor)
Perform the euclidian division of two polynomials.

Parameters:
divisor - denominator polynomial
Returns:
an array of two elements containing the quotient and the remainder of the division

toComplexPolynomial

public ComplexPolynomial toComplexPolynomial()

toExactRealPolynomial

public ExactRealPolynomial toExactRealPolynomial()

toExactComplexPolynomial

public ExactComplexPolynomial toExactComplexPolynomial()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

rootsToPolynomial

public static DoublePolynomial rootsToPolynomial(double[] roots)

roots

public Complex[] roots()

quadratic

public static Complex[] quadratic(double c,
                                  double b,
                                  double a)

cubic

public static Complex[] cubic(double d,
                              double c,
                              double b,
                              double a)