randpoly - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


randpoly

random polynomial generator

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

randpoly(vars, opts)

Parameters

vars

-

indeterminate or list or set of indeterminates

opts

-

(optional) equations or names specifying properties

Description

• 

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.

Examples

randpolyx

7x5+22x455x394x2+87x56

(1)

randpolyx,y

75x4y17x2y+80x244xy+71y282x

(2)

randpolyx,y,terms=10

49x547x3y28x3y29x2y2+95xy3+11y423x2y+10xy261y3+98

(3)

randpolyx,y,dense,degree=4

40x481x3y+68x2y251xy3+y4+91x310x2y+77xy2+55y3+31x2+95xy28y2+x+16y+30

(4)

randpolyx,y,homogeneous

90x5+x2y3178xy4

(5)

randpolyx,y,z,dense,homogeneous,degree=2

48x228xy+53zx10y2+13yz+5z2

(6)

randpolyx,sinx,cosx

83sinx2cosx+98x3sinxcosx48x2sinx2cosx19x2cosx3+62sinx4cosx+37sinxcosx4

(7)

randpolyz,expons=rand5..5

86z2+64z473z4

(8)

randpoly([x], coeffs = proc() randpoly(y) end proc);

71y547y439y353y272y97x5+33y5+10y4+7y389y2+65y+12x4+25y596y4+50y360y242y+7x3+89y570y4+34y368y260y+16x2+52y520y44y389y277y+69x+80y5+28y442y333y2+21y35

(9)

RandomToolsGeneratepolynomintegerrange=10..10,x,degree=4

6x4+9x37x29x6

(10)

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.

randpolyx,coeffs=rand1..1,terms=100

x5+x3x2+x+1

(11)

randpolyx,coeffs=rand1..1,expons=rand2,terms=100

145x

(12)

See Also

LinearAlgebra[RandomMatrix]

LinearAlgebra[RandomVector]

rand

RandomTools