org.spaceroots.mantissa.algebra
Class Polynomial.Double

java.lang.Object
  extended byorg.spaceroots.mantissa.algebra.Polynomial
      extended byorg.spaceroots.mantissa.algebra.Polynomial.Double
All Implemented Interfaces:
Serializable
Enclosing class:
Polynomial

public static class Polynomial.Double
extends Polynomial

This class implements polynomials with one unknown and real coefficients.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.spaceroots.mantissa.algebra.Polynomial
Polynomial.DivisionResult, Polynomial.Double, Polynomial.Rational
 
Field Summary
protected  double[] a
          Coefficients array.
 
Constructor Summary
Polynomial.Double()
          Simple constructor.
Polynomial.Double(double value)
          Simple constructor.
Polynomial.Double(double[] a)
          Simple constructor.
Polynomial.Double(double a1, double a0)
          Simple constructor.
Polynomial.Double(double a2, double a1, double a0)
          Simple constructor.
Polynomial.Double(double a3, double a2, double a1, double a0)
          Simple constructor.
Polynomial.Double(double c, int degree)
          Simple constructor.
Polynomial.Double(long value)
          Simple constructor.
Polynomial.Double(long a1, long a0)
          Simple constructor.
Polynomial.Double(long a2, long a1, long a0)
          Simple constructor.
Polynomial.Double(long a3, long a2, long a1, long a0)
          Simple constructor.
Polynomial.Double(Polynomial.Rational r)
          Simple constructor.
 
Method Summary
 Polynomial.Double add(Polynomial.Double p)
          Add a polynomial to the instance
 double[] getCoefficients()
          Get the coefficients of the polynomial.
 int getDegree()
          Get the polynomial degree.
 Polynomial getDerivative()
          Get the derivative of the instance with respect to the unknown.
 boolean isIdentity()
          Check if the instance is the identity polynomial.
 boolean isOne()
          Check if the instance is the constant unit polynomial.
 boolean isZero()
          Check if the instance is the null polynomial.
 Polynomial multiply(double r)
          Multiply the instance by a constant.
 Polynomial multiply(long l)
          Multiply the instance by a constant.
 Polynomial.Double multiply(Polynomial.Double p)
          Multiply the instance by a polynomial.
 Polynomial multiply(RationalNumber r)
          Multiply the instance by a constant.
 Polynomial negate()
          Negate the instance.
 Polynomial.Double subtract(Polynomial.Double p)
          Subtract a polynomial from the instance.
 String toString()
          Returns a string representation of the polynomial.
 double valueAt(double x)
          Get the value of the polynomial for a specified unknown.
 
Methods inherited from class org.spaceroots.mantissa.algebra.Polynomial
divide, divide, divide, multiply
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

a

protected double[] a
Coefficients array.

Constructor Detail

Polynomial.Double

public Polynomial.Double()
Simple constructor. Build a null polynomial


Polynomial.Double

public Polynomial.Double(long value)
Simple constructor. Build a constant polynomial

Parameters:
value - constant value of the polynomial

Polynomial.Double

public Polynomial.Double(double value)
Simple constructor. Build a constant polynomial

Parameters:
value - constant value of the polynomial

Polynomial.Double

public Polynomial.Double(long a1,
                         long a0)
Simple constructor. Build a first degree polynomial

Parameters:
a1 - leeding degree coefficient
a0 - constant term

Polynomial.Double

public Polynomial.Double(double a1,
                         double a0)
Simple constructor. Build a first degree polynomial

Parameters:
a1 - leeding degree coefficient
a0 - constant term

Polynomial.Double

public Polynomial.Double(long a2,
                         long a1,
                         long a0)
Simple constructor. Build a second degree polynomial

Parameters:
a2 - leeding degree coefficient
a1 - first degree coefficient
a0 - constant term

Polynomial.Double

public Polynomial.Double(double a2,
                         double a1,
                         double a0)
Simple constructor. Build a second degree polynomial

Parameters:
a2 - leeding degree coefficient
a1 - first degree coefficient
a0 - constant term

Polynomial.Double

public Polynomial.Double(long a3,
                         long a2,
                         long a1,
                         long a0)
Simple constructor. Build a third degree polynomial

Parameters:
a3 - leeding degree coefficient
a2 - second degree coefficient
a1 - first degree coefficient
a0 - constant term

Polynomial.Double

public Polynomial.Double(double a3,
                         double a2,
                         double a1,
                         double a0)
Simple constructor. Build a third degree polynomial

Parameters:
a3 - leeding degree coefficient
a2 - second degree coefficient
a1 - first degree coefficient
a0 - constant term

Polynomial.Double

public Polynomial.Double(double[] a)
Simple constructor. Build a polynomial from its coefficients

Parameters:
a - coefficients array, the a[0] array element is the constant term while the a[a.length-1] element is the leeding degree coefficient. The array is copied in a new array, so it can be changed once the constructor as returned.

Polynomial.Double

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

Parameters:
c - coefficient
degree - degree associated with the coefficient

Polynomial.Double

public Polynomial.Double(Polynomial.Rational r)
Simple constructor. Build a Polynomial.Double from a Polynomial.Rational

Parameters:
r - a rational polynomial
Method Detail

isZero

public boolean isZero()
Check if the instance is the null polynomial.

Specified by:
isZero in class Polynomial
Returns:
true if the polynomial is null

isOne

public boolean isOne()
Check if the instance is the constant unit polynomial.

Specified by:
isOne in class Polynomial
Returns:
true if the polynomial is the constant unit polynomial

isIdentity

public boolean isIdentity()
Check if the instance is the identity polynomial.

Specified by:
isIdentity in class Polynomial
Returns:
true if the polynomial is the identity polynomial

getDegree

public int getDegree()
Get the polynomial degree.

Specified by:
getDegree in class Polynomial
Returns:
degree

getCoefficients

public double[] getCoefficients()
Get the coefficients of the polynomial.

Returns:
a copy of the coefficients array, the array element at index 0 is the constant term while the element at index a.length-1 is the leading degree coefficient

add

public Polynomial.Double add(Polynomial.Double p)
Add a polynomial to the instance

Parameters:
p - polynomial to add
Returns:
a new polynomial which is the sum of the instance and p

subtract

public Polynomial.Double subtract(Polynomial.Double p)
Subtract a polynomial from the instance.

Parameters:
p - polynomial to subtract
Returns:
a new polynomial which is the difference the instance minus p

negate

public Polynomial negate()
Negate the instance.

Specified by:
negate in class Polynomial
Returns:
a new polynomial

multiply

public Polynomial.Double multiply(Polynomial.Double p)
Multiply the instance by a polynomial.

Parameters:
p - polynomial to multiply by
Returns:
a new polynomial

multiply

public Polynomial multiply(long l)
Multiply the instance by a constant.

Specified by:
multiply in class Polynomial
Parameters:
l - constant to multiply by
Returns:
a new polynomial

multiply

public Polynomial multiply(RationalNumber r)
Multiply the instance by a constant.

Specified by:
multiply in class Polynomial
Parameters:
r - constant to multiply by
Returns:
a new polynomial

multiply

public Polynomial multiply(double r)
Multiply the instance by a constant.

Parameters:
r - constant to multiply by
Returns:
a new polynomial

valueAt

public double valueAt(double x)
Get the value of the polynomial for a specified unknown.

Specified by:
valueAt in class Polynomial
Parameters:
x - value of the unknown
Returns:
value of the polynomial

getDerivative

public Polynomial getDerivative()
Get the derivative of the instance with respect to the unknown. The derivative of a n degree polynomial is a n-1 degree polynomial of the same type.

Specified by:
getDerivative in class Polynomial
Returns:
a new polynomial which is the derivative of the instance

toString

public String toString()
Returns a string representation of the polynomial.

The representation is user oriented. Terms are displayed lowest degrees first. The multiplications signs, coefficients equals to one and null terms are not displayed (except if the polynomial is 0, in which case the 0 constant term is displayed). Addition of terms with negative coefficients are replaced by subtraction of terms with positive coefficients except for the first displayed term (i.e. we display -3 for a constant negative polynomial, but 1 - 3 x + x^2 if the negative coefficient is not the first one displayed).

Returns:
a string representation of the polynomial


Copyright © 2001-2007 Luc Maisonobe. All Rights Reserved.