Documentation Center |
Create a random polynomial
This functionality does not run in MATLAB.
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 user-defined 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);
Degree |
Option, specified as Degree = k The maximum degree the result can have in each variable. k must be a nonnegative integer. Default is 6. |
Terms |
Option, specified as Terms = t Makes polylib::randpoly generate the sum of t random terms. t must be a positive integer or infinity. If t equals infinity, polylib::randpoly returns a dense polynomial. Default is 5. |
Coeffs |
Option, specified as Coeffs = f Create the coefficients of the result by calling f(). |
Monic |
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.