UniVariatePolynomial¶
-
class
UniVariatePolynomial
(*args)¶ Base class for univariate polynomials.
- Parameters
- coefficientssequence of float
Polynomial coefficients in increasing polynomial order.
Examples
>>> import openturns as ot
Create a univariate polynomial from a list of coefficients:
>>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> print(P) 1 + 2 * X + 3 * X^2
Univariate polynomials are of course callable:
>>> print(P(1.0)) 6.0
Addition, subtraction and multiplication of univariate polynomials:
>>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> Q = ot.UniVariatePolynomial([1.0, 2.0]) >>> print('(%s) + (%s) = %s' % (P, Q, P + Q)) (1 + 2 * X + 3 * X^2) + (1 + 2 * X) = 2 + 4 * X + 3 * X^2 >>> print('(%s) - (%s) = %s' % (P, Q, P - Q)) (1 + 2 * X + 3 * X^2) - (1 + 2 * X) = 3 * X^2 >>> print('(%s) * (%s) = %s' % (P, Q, P * Q)) (1 + 2 * X + 3 * X^2) * (1 + 2 * X) = 1 + 4 * X + 7 * X^2 + 6 * X^3
Methods
__call__
(self, \*args)Call self as a function.
derivate
(self)Build the first-order derivative polynomial.
draw
(self, xMin, xMax, pointNumber)Draw the function.
getClassName
(self)Accessor to the object’s name.
getCoefficients
(self)Accessor to the polynomials’s coefficients.
getDegree
(self)Accessor to the polynomials’s degree.
getId
(self)Accessor to the object’s id.
getImplementation
(self)Accessor to the underlying implementation.
getName
(self)Accessor to the object’s name.
getRoots
(self)Compute the roots of the polynomial.
gradient
(self, x)Compute the gradient at point .
hessian
(self, x)Compute the hessian at point .
incrementDegree
(self[, degree])Multiply the polynomial by .
setCoefficients
(self, coefficients)Accessor to the polynomials’s coefficients.
setName
(self, name)Accessor to the object’s name.
-
__init__
(self, \*args)¶ Initialize self. See help(type(self)) for accurate signature.
-
derivate
(self)¶ Build the first-order derivative polynomial.
- Returns
- derivated_polynomial
Univariate
The first-order derivated polynomial.
- derivated_polynomial
Examples
>>> import openturns as ot >>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> print(P.derivate()) 2 + 6 * X
-
draw
(self, xMin, xMax, pointNumber)¶ Draw the function.
- Parameters
- x_minfloat, optional
The starting value that is used for meshing the x-axis.
- x_maxfloat, optional,
The ending value that is used for meshing the x-axis.
- n_pointsint, optional
The number of points that is used for meshing the x-axis.
Examples
>>> import openturns as ot >>> from openturns.viewer import View >>> f = ot.UniVariatePolynomial([1.0, 2.0, -3.0, 5.0]) >>> View(f.draw(-10.0, 10.0, 100)).show()
-
getClassName
(self)¶ Accessor to the object’s name.
- Returns
- class_namestr
The object class name (object.__class__.__name__).
-
getCoefficients
(self)¶ Accessor to the polynomials’s coefficients.
- Returns
- coefficients
Point
Polynomial coefficients in increasing polynomial order.
- coefficients
See also
Examples
>>> import openturns as ot >>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> print(P.getCoefficients()) [1,2,3]
-
getDegree
(self)¶ Accessor to the polynomials’s degree.
- Returns
- degreeint
Polynomial’s degree.
Examples
>>> import openturns as ot >>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> print(P.getDegree()) 2
-
getId
(self)¶ Accessor to the object’s id.
- Returns
- idint
Internal unique identifier.
-
getImplementation
(self)¶ Accessor to the underlying implementation.
- Returns
- implImplementation
The implementation class.
-
getName
(self)¶ Accessor to the object’s name.
- Returns
- namestr
The name of the object.
-
getRoots
(self)¶ Compute the roots of the polynomial.
- Returns
- rootslist of complex values
Polynomial’s roots.
Examples
>>> import openturns as ot >>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> print(P.getRoots()) [(-0.333333,0.471405),(-0.333333,-0.471405)]
-
gradient
(self, x)¶ Compute the gradient at point .
- Returns
- gradientfloat
The value of the function’s first-order derivative at point .
Examples
>>> import openturns as ot >>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> print(P.gradient(1.0)) 8.0
-
hessian
(self, x)¶ Compute the hessian at point .
- Parameters
- xfloat
Input value.
- Returns
- hessianfloat
The value of the function’s second-order derivative at point .
-
incrementDegree
(self, degree=1)¶ Multiply the polynomial by .
- Parameters
- degreeint, optional
The incremented degree . Default uses .
- Returns
- incremented_degree_polynomial
UniVariatePolynomial
Polynomial with incremented degree.
- incremented_degree_polynomial
Examples
>>> import openturns as ot >>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> print(P.incrementDegree()) X + 2 * X^2 + 3 * X^3 >>> print(P.incrementDegree(2)) X^2 + 2 * X^3 + 3 * X^4
-
setCoefficients
(self, coefficients)¶ Accessor to the polynomials’s coefficients.
- Parameters
- coefficientssequence of float
Polynomial coefficients in increasing polynomial order.
See also
Examples
>>> import openturns as ot >>> P = ot.UniVariatePolynomial([1.0, 2.0, 3.0]) >>> P.setCoefficients([4.0, 2.0, 1.0]) >>> print(P) 4 + 2 * X + X^2
-
setName
(self, name)¶ Accessor to the object’s name.
- Parameters
- namestr
The name of the object.