randpoly
random polynomial generator
Calling Sequence
Parameters
Description
Examples
randpoly(vars, opts)
vars
-
indeterminate or list or set of indeterminates
opts
(optional) equations or names specifying properties
A call to randpoly generates a random polynomial in vars. It is useful for generating test problems for debugging, testing, and demonstration purposes. Several options can be specified, determining the form of the polynomial. This allows for quite general expressions with certain properties.
The first argument vars specifies the variables in which the polynomial is to be generated. If vars is a single variable, a univariate polynomial in that variable is generated. If vars is a list or set of variables, then a multivariate polynomial is generated.
The possible options (and their default values) are:
Option
Use
Default Value
coeffs
generate the coefficients
rand(-99..99)
expons
generate the exponents
rand(6)
terms
number of terms generated
6
degree
total degree for a dense polynomial
5
dense
the polynomial is to be dense
sparse
homogeneous
the polynomial is to be homogeneous
The terms option is intended for specifying the number of terms in sparse polynomials, where the numbers of terms is often significantly smaller than the maximum number of possible terms. The terms option will be overridden by the degree option. A call randpoly(x, terms=7) will return a polynomial with six terms, since the default degree is five. If you want a dense polynomial, simply use the dense option.
Note: If you use the terms option, some of the terms generated may have the same exponents. In this case, the corresponding coefficients will be added in the return value. As a result, the number of terms you see in the result is lower than the number actually generated, and the coefficients may be outside of the range specified. This is demonstrated in one of the examples below; see the note there.
randpoly⁡x
−7⁢x5+22⁢x4−55⁢x3−94⁢x2+87⁢x−56
randpoly⁡x,y
−75⁢x4⁢y−17⁢x2⁢y+80⁢x2−44⁢x⁢y+71⁢y2−82⁢x
randpoly⁡x,y,terms=10
−49⁢x5−47⁢x3⁢y2−8⁢x3⁢y−29⁢x2⁢y2+95⁢x⁢y3+11⁢y4−23⁢x2⁢y+10⁢x⁢y2−61⁢y3+98
randpoly⁡x,y,dense,degree=4
40⁢x4−81⁢x3⁢y+68⁢x2⁢y2−51⁢x⁢y3+y4+91⁢x3−10⁢x2⁢y+77⁢x⁢y2+55⁢y3+31⁢x2+95⁢x⁢y−28⁢y2+x+16⁢y+30
randpoly⁡x,y,homogeneous
90⁢x5+x2⁢y3−178⁢x⁢y4
randpoly⁡x,y,z,dense,homogeneous,degree=2
−48⁢x2−28⁢x⁢y+53⁢z⁢x−10⁢y2+13⁢y⁢z+5⁢z2
randpoly⁡x,sin⁡x,cos⁡x
−83⁢sin⁡x2⁢cos⁡x+98⁢x3⁢sin⁡x⁢cos⁡x−48⁢x2⁢sin⁡x2⁢cos⁡x−19⁢x2⁢cos⁡x3+62⁢sin⁡x4⁢cos⁡x+37⁢sin⁡x⁢cos⁡x4
randpoly⁡z,expons=rand⁡−5..5
86z2+64⁢z4−73z4
randpoly([x], coeffs = proc() randpoly(y) end proc);
71⁢y5−47⁢y4−39⁢y3−53⁢y2−72⁢y−97⁢x5+33⁢y5+10⁢y4+7⁢y3−89⁢y2+65⁢y+12⁢x4+−25⁢y5−96⁢y4+50⁢y3−60⁢y2−42⁢y+7⁢x3+−89⁢y5−70⁢y4+34⁢y3−68⁢y2−60⁢y+16⁢x2+52⁢y5−20⁢y4−4⁢y3−89⁢y2−77⁢y+69⁢x+80⁢y5+28⁢y4−42⁢y3−33⁢y2+21⁢y−35
RandomToolsGenerate⁡polynom⁡integer⁡range=−10..10,x,degree=4
6⁢x4+9⁢x3−7⁢x2−9⁢x−6
Note: The options coeffs and expons are used to generate the individual terms, which are added to form the polynomial. Thus, the generated polynomial may have coefficients outside the specified range. This is more likely if the requested number of terms is significantly larger than the required degree.
randpoly⁡x,coeffs=rand⁡−1..1,terms=100
x5+x3−x2+x+1
randpoly⁡x,coeffs=rand⁡−1..1,expons=rand⁡2,terms=100
−14−5⁢x
See Also
LinearAlgebra[RandomMatrix]
LinearAlgebra[RandomVector]
rand
RandomTools
Download Help Document