polylib
::randpoly
Create a random polynomial
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
polylib::randpoly() polylib::randpoly(<list
>, <ring
>, <Degree = n
>, <Terms = k
>, <Coeffs = f
>, <Monic>)
polylib::randpoly()
returns a univariate
random polynomial with integer coefficients; the global identifier x
is
used as the indeterminate.
polylib::randpoly(list)
returns a random
polynomial in all indeterminates given in list
.
polylib::randpoly(list, ring)
returns a
random polynomial in the indeterminates given in list
over
the coefficient ring ring
.
See poly
for
a detailed description of possible indeterminates and coefficient
rings.
The polynomial is created by randomly choosing as many exponents
as specified through the option Terms
and then
choosing random coefficients. It may of course happen that for some
coefficient 0 is chosen,
therefore the actual number of terms in the result can be smaller
than the value of the option Terms
.
If the option Coeffs=f
is given, the random
coefficients are generated by calling f()
. Otherwise,
if ring
is Expr
, the coefficients
will be random integers in the range  999, …,
999. If ring
is a userdefined
domain, it must have a method "random"
to create
the coefficients if no function is given.
If the option Monic
is given, the resulting
polynomial has exactly the specified degree and the leading coefficient
is 1.
If the requested number of terms exceeds the maximal possible number of terms for the specified degree and number of variables, a warning is emitted and a dense polynomial is created.
Unless a generator is specified through the option Coeffs
, polylib::randpoly
uses random
to create the
exponents and coefficients. Therefore it is sensitive to the environment
variable SEED
.
We generate a univariate random polynomial in the indeterminate z
,
and use the default values for the other options. Therefore the polynomial
has integer coefficients, is of degree 5, and has 6 terms.
polylib::randpoly([z])
We create a bivariate random polynomial over the finite field
with 7 elements. This works because Dom::IntegerMod
has a "random"
slot
that generates random elements:
polylib::randpoly([x,y],Dom::IntegerMod(7),Degree=3,Terms=4);

List of indeterminates 

Coefficient ring 

Option, specified as The maximum degree the result can have in each variable. 

Option, specified as Makes 

Option, specified as Create the coefficients of the result by calling 

The created polynomial is monic, i.e., the leading coefficient is 1. 
Polynomial in the given indeterminates over the given ring.
If no list of indeterminates is given, [x]
is used.
If no ring is given, Expr
is used.