JScience v4.3

## org.jscience.mathematics.function Class Polynomial<R extends Ring<R>>

```java.lang.Object org.jscience.mathematics.function.Function<R,R> org.jscience.mathematics.function.Polynomial<R>
```
All Implemented Interfaces:
java.io.Serializable, javolution.lang.Immutable, javolution.lang.Realtime, javolution.lang.ValueType, GroupAdditive<Polynomial<R>>, Ring<Polynomial<R>>, Structure<Polynomial<R>>
Direct Known Subclasses:
Constant

`public class Polynomial<R extends Ring<R>>extends Function<R,R>implements Ring<Polynomial<R>>`

This class represents a mathematical expression involving a sum of powers in one or more `variables` multiplied by coefficients (such as `x² + x·y + 3y²`).

Polynomials are characterized by the type of variable they operate upon. For example:

``````           Variable<Amount<?>> varX = new Variable.Local<Amount<?>>("x");
Polynomial<Amount<?>> x = Polynomial.valueOf(Amount.valueOf(1, SI.METER), varX);
and
Variable<Complex> varX = new Variable.Local<Complex>("x");
Polynomial<Complex> x = Polynomial.valueOf(Complex.ONE, varX);``````
are two different polynomials, the first one operates on physical `measures`, whereas the second operates on `complex` numbers.

Terms (others than `ONE`) having zero (additive identity) for coefficient are automatically removed.

Version:
3.1, April 1, 2006
Author:
Jean-Marie Dautelle
Serialized Form

Method Summary
``` <Z> Function<Z,R> ``` `compose(Function<Z,R> that)`
Returns the composition of this function with the one specified.
` Polynomial<R>` `compose(Polynomial<R> that)`
Returns the composition of this polynomial with the one specified.
` Polynomial<R>` `copy()`
Returns a copy of this polynomial `allocated` by the calling thread (possibly on the stack).
` Polynomial<R>` `differentiate(Variable<R> v)`
Returns the first derivative of this function with respect to the specified variable.
` boolean` `equals(java.lang.Object obj)`
Indicates if this function is equals to the specified object.
` R` `evaluate()`
Evaluates this function using its `variables` current values.
` R` `getCoefficient(Term term)`
Returns the coefficient for the specified term.
` int` `getOrder(Variable<R> v)`
Returns the order of this polynomial for the specified variable.
` java.util.Set<Term>` `getTerms()`
Returns the terms of this polynomial.
` java.util.List<Variable<R>>` `getVariables()`
Returns a lexically ordered list of the variables (or arguments) for this function (empty list for constant functions).
` int` `hashCode()`
Returns the hash code for this function (consistent with `Function.equals(Object)`.
` Polynomial<R>` `integrate(Variable<R> v)`
Returns an integral of this function with respect to the specified variable.
` Function<R,R>` `minus(Function<R,R> that)`
Returns the difference of this function with the one specified.
` Polynomial<R>` `minus(Polynomial<R> that)`
Returns the difference of two polynomials.
` Polynomial<R>` `opposite()`
Returns the opposite of this polynomial.
` Function<R,R>` `plus(Function<R,R> that)`
Returns the sum of this function with the one specified.
` Polynomial<R>` `plus(Polynomial<R> that)`
Returns the sum of two polynomials.
` Polynomial<R>` `plus(R constantValue)`
Returns the sum of this polynomial with a constant polynomial having the specified value (convenience method).
` Polynomial<R>` `pow(int n)`
Returns this function raised at the specified exponent.
` Function<R,R>` `times(Function<R,R> that)`
Returns the product of this function with the one specified.
` Polynomial<R>` `times(Polynomial<R> that)`
Returns the product of two polynomials.
` Polynomial<R>` `times(R constantValue)`
Returns the product of this polynomial with a constant polynomial having the specified value (convenience method).
` javolution.text.Text` `toText()`
Returns the textual representation of this real-time object (equivalent to `toString` except that the returned value can be allocated from the local context space).
```static <R extends Ring<R>> Polynomial<R> ``` ```valueOf(R coefficient, Term term)```
Returns a polynomial corresponding to the specified `term` with the specified coefficient multiplier.
```static <R extends Ring<R>> Polynomial<R> ``` ```valueOf(R coefficient, Variable<R> variable)```
Returns an univariate polynomial of degree one with the specified coefficient multiplier.

Methods inherited from class org.jscience.mathematics.function.Function
`divide, evaluate, evaluate, getVariable, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Method Detail

### valueOf

```public static <R extends Ring<R>> Polynomial<R> valueOf(R coefficient,
Variable<R> variable)```
Returns an univariate polynomial of degree one with the specified coefficient multiplier.

Parameters:
`coefficient` - the coefficient for the variable of degree 1.
`variable` - the variable for this polynomial.
Returns:
`valueOf(coefficient, Term.valueOf(variable, 1))`

### valueOf

```public static <R extends Ring<R>> Polynomial<R> valueOf(R coefficient,
Term term)```
Returns a polynomial corresponding to the specified `term` with the specified coefficient multiplier.

Parameters:
`coefficient` - the coefficient multiplier.
`term` - the term multiplicand.
Returns:
`coefficient * term`

### getTerms

`public java.util.Set<Term> getTerms()`
Returns the terms of this polynomial.

Returns:
this polynomial's terms.

### getCoefficient

`public final R getCoefficient(Term term)`
Returns the coefficient for the specified term.

Parameters:
`term` - the term for which the coefficient is returned.
Returns:
the coefficient for the specified term or `null` if this polynomial does not contain the specified term.

### getOrder

`public int getOrder(Variable<R> v)`
Returns the order of this polynomial for the specified variable.

Returns:
the polynomial order relative to the specified variable.

### plus

`public Polynomial<R> plus(R constantValue)`
Returns the sum of this polynomial with a constant polynomial having the specified value (convenience method).

Parameters:
`constantValue` - the value of the constant polynomial to add.
Returns:
`this + Constant.valueOf(constantValue)`

### times

`public Polynomial<R> times(R constantValue)`
Returns the product of this polynomial with a constant polynomial having the specified value (convenience method).

Parameters:
`constantValue` - the value of the constant polynomial to multiply.
Returns:
`this · Constant.valueOf(constantValue)`

### plus

`public Polynomial<R> plus(Polynomial<R> that)`
Returns the sum of two polynomials.

Specified by:
`plus` in interface `GroupAdditive<Polynomial<R extends Ring<R>>>`
Parameters:
`that` - the polynomial being added.
Returns:
`this + that`

### opposite

`public Polynomial<R> opposite()`
Returns the opposite of this polynomial.

Specified by:
`opposite` in interface `GroupAdditive<Polynomial<R extends Ring<R>>>`
Returns:
` - this`

### minus

`public Polynomial<R> minus(Polynomial<R> that)`
Returns the difference of two polynomials.

Parameters:
`that` - the polynomial being subtracted.
Returns:
`this - that`

### times

`public Polynomial<R> times(Polynomial<R> that)`
Returns the product of two polynomials.

Specified by:
`times` in interface `Ring<Polynomial<R extends Ring<R>>>`
Parameters:
`that` - the polynomial multiplier.
Returns:
`this · that`

### compose

`public Polynomial<R> compose(Polynomial<R> that)`
Returns the composition of this polynomial with the one specified.

Parameters:
`that` - the polynomial for which the return value is passed as argument to this function.
Returns:
the polynomial `(this o that)`
Throws:
`FunctionException` - if this function is not univariate.

### compose

`public <Z> Function<Z,R> compose(Function<Z,R> that)`
Description copied from class: `Function`
Returns the composition of this function with the one specified.

Overrides:
`compose` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Parameters:
`that` - the function for which the return value is passed as argument to this function.
Returns:
the function `(this o that)`

### differentiate

`public Polynomial<R> differentiate(Variable<R> v)`
Description copied from class: `Function`
Returns the first derivative of this function with respect to the specified variable.

Overrides:
`differentiate` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Parameters:
`v` - the variable for which the derivative is calculated.
Returns:
`d[this]/dv`
Derivative -- from MathWorld

### integrate

`public Polynomial<R> integrate(Variable<R> v)`
Description copied from class: `Function`
Returns an integral of this function with respect to the specified variable.

Overrides:
`integrate` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Parameters:
`v` - the variable for which the integral is calculated.
Returns:
`S[this·dv]`
Integral -- from MathWorld

### plus

`public Function<R,R> plus(Function<R,R> that)`
Description copied from class: `Function`
Returns the sum of this function with the one specified.

Overrides:
`plus` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Parameters:
`that` - the function to be added.
Returns:
`this + that`.

### minus

`public Function<R,R> minus(Function<R,R> that)`
Description copied from class: `Function`
Returns the difference of this function with the one specified.

Overrides:
`minus` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Parameters:
`that` - the function to be subtracted.
Returns:
`this - that`.

### times

`public Function<R,R> times(Function<R,R> that)`
Description copied from class: `Function`
Returns the product of this function with the one specified.

Overrides:
`times` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Parameters:
`that` - the function multiplier.
Returns:
`this · that`.

### pow

`public Polynomial<R> pow(int n)`
Description copied from class: `Function`
Returns this function raised at the specified exponent.

Overrides:
`pow` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Parameters:
`n` - the exponent.
Returns:
`thisn`

### getVariables

`public java.util.List<Variable<R>> getVariables()`
Description copied from class: `Function`
Returns a lexically ordered list of the variables (or arguments) for this function (empty list for constant functions).

Specified by:
`getVariables` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Returns:
this function current unset variables (sorted).

### evaluate

`public R evaluate()`
Description copied from class: `Function`
Evaluates this function using its `variables` current values.

Specified by:
`evaluate` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Returns:
the evaluation of this function.

### equals

`public boolean equals(java.lang.Object obj)`
Description copied from class: `Function`
Indicates if this function is equals to the specified object.

Overrides:
`equals` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Parameters:
`obj` - the object to be compared with.
Returns:
`true` if this function and the specified argument represent the same function; `false` otherwise.

### hashCode

`public int hashCode()`
Description copied from class: `Function`
Returns the hash code for this function (consistent with `Function.equals(Object)`.

Overrides:
`hashCode` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Returns:
this function hash code.

### toText

`public javolution.text.Text toText()`
Description copied from class: `Function`
Returns the textual representation of this real-time object (equivalent to `toString` except that the returned value can be allocated from the local context space).

Specified by:
`toText` in interface `javolution.lang.Realtime`
Specified by:
`toText` in class `Function<R extends Ring<R>,R extends Ring<R>>`
Returns:
this object's textual representation.

### copy

`public Polynomial<R> copy()`
Returns a copy of this polynomial `allocated` by the calling thread (possibly on the stack).

Specified by:
`copy` in interface `javolution.lang.ValueType`
Returns:
an identical and independant copy of this polynomial.

JScience v4.3