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:
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 asx² + x·y + 3y²
).Polynomials are characterized by the type of variable they operate upon. For example:[code] Variable
> varX = new Variable.Local >("x"); Polynomial > x = Polynomial.valueOf(Amount.valueOf(1, SI.METER), varX); and Variable varX = new Variable.Local ("x"); Polynomial x = Polynomial.valueOf(Complex.ONE, varX);[/code] are two different polynomials, the first one operates on physical measures
, whereas the second operates oncomplex
numbers.Terms (others than
ONE
) having zero (additive identity) for coefficient are automatically removed.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <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 polynomialallocated
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(Object obj)
Indicates if this function is equals to the specified object.R
evaluate()
Evaluates this function using itsvariables
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.Set<Term>
getTerms()
Returns the terms of this polynomial.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 withFunction.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 totoString
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 specifiedterm
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.
-
-
-
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 specifiedterm
with the specified coefficient multiplier.- Parameters:
coefficient
- the coefficient multiplier.term
- the term multiplicand.- Returns:
coefficient * term
-
getTerms
public 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 interfaceGroupAdditive<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 interfaceGroupAdditive<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.
-
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.
-
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 classFunction<R extends Ring<R>,R extends Ring<R>>
- Parameters:
v
- the variable for which the derivative is calculated.- Returns:
d[this]/dv
- See Also:
- 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.
-
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.
-
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.
-
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.
-
pow
public Polynomial<R> pow(int n)
Description copied from class:Function
Returns this function raised at the specified exponent.
-
getVariables
public 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).
-
evaluate
public R evaluate()
Description copied from class:Function
Evaluates this function using itsvariables
current values.
-
equals
public boolean equals(Object obj)
Description copied from class:Function
Indicates if this function is equals to the specified object.
-
hashCode
public int hashCode()
Description copied from class:Function
Returns the hash code for this function (consistent withFunction.equals(Object)
.
-
toText
public javolution.text.Text toText()
Description copied from class:Function
Returns the textual representation of this real-time object (equivalent totoString
except that the returned value can be allocated from the local context space).
-
copy
public Polynomial<R> copy()
Returns a copy of this polynomialallocated
by the calling thread (possibly on the stack).- Specified by:
copy
in interfacejavolution.lang.ValueType
- Returns:
- an identical and independant copy of this polynomial.
-
-