randpoly - Maple Programming Help

Home : Support : Online Help : Mathematics : Algebra : Polynomials : randpoly

randpoly

random polynomial generator

 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

 > $\mathrm{randpoly}\left(x\right)$
 ${-}{7}{}{{x}}^{{5}}{+}{22}{}{{x}}^{{4}}{-}{55}{}{{x}}^{{3}}{-}{94}{}{{x}}^{{2}}{+}{87}{}{x}{-}{56}$ (1)
 > $\mathrm{randpoly}\left(\left[x,y\right]\right)$
 ${-}{75}{}{{x}}^{{4}}{}{y}{-}{17}{}{{x}}^{{2}}{}{y}{+}{80}{}{{x}}^{{2}}{-}{44}{}{x}{}{y}{+}{71}{}{{y}}^{{2}}{-}{82}{}{x}$ (2)
 > $\mathrm{randpoly}\left(\left[x,y\right],\mathrm{terms}=10\right)$
 ${-}{49}{}{{x}}^{{5}}{-}{47}{}{{x}}^{{3}}{}{{y}}^{{2}}{-}{8}{}{{x}}^{{3}}{}{y}{-}{29}{}{{x}}^{{2}}{}{{y}}^{{2}}{+}{95}{}{x}{}{{y}}^{{3}}{+}{11}{}{{y}}^{{4}}{-}{23}{}{{x}}^{{2}}{}{y}{+}{10}{}{x}{}{{y}}^{{2}}{-}{61}{}{{y}}^{{3}}{+}{98}$ (3)
 > $\mathrm{randpoly}\left(\left[x,y\right],\mathrm{dense},\mathrm{degree}=4\right)$
 ${40}{}{{x}}^{{4}}{-}{81}{}{{x}}^{{3}}{}{y}{+}{68}{}{{x}}^{{2}}{}{{y}}^{{2}}{-}{51}{}{x}{}{{y}}^{{3}}{+}{{y}}^{{4}}{+}{91}{}{{x}}^{{3}}{-}{10}{}{{x}}^{{2}}{}{y}{+}{77}{}{x}{}{{y}}^{{2}}{+}{55}{}{{y}}^{{3}}{+}{31}{}{{x}}^{{2}}{+}{95}{}{x}{}{y}{-}{28}{}{{y}}^{{2}}{+}{x}{+}{16}{}{y}{+}{30}$ (4)
 > $\mathrm{randpoly}\left(\left[x,y\right],\mathrm{homogeneous}\right)$
 ${90}{}{{x}}^{{5}}{+}{{x}}^{{2}}{}{{y}}^{{3}}{-}{178}{}{x}{}{{y}}^{{4}}$ (5)
 > $\mathrm{randpoly}\left(\left[x,y,z\right],\mathrm{dense},\mathrm{homogeneous},\mathrm{degree}=2\right)$
 ${-}{48}{}{{x}}^{{2}}{-}{28}{}{x}{}{y}{+}{53}{}{z}{}{x}{-}{10}{}{{y}}^{{2}}{+}{13}{}{y}{}{z}{+}{5}{}{{z}}^{{2}}$ (6)
 > $\mathrm{randpoly}\left(\left[x,\mathrm{sin}\left(x\right),\mathrm{cos}\left(x\right)\right]\right)$
 ${-}{83}{}{{\mathrm{sin}}{}\left({x}\right)}^{{2}}{}{\mathrm{cos}}{}\left({x}\right){+}{98}{}{{x}}^{{3}}{}{\mathrm{sin}}{}\left({x}\right){}{\mathrm{cos}}{}\left({x}\right){-}{48}{}{{x}}^{{2}}{}{{\mathrm{sin}}{}\left({x}\right)}^{{2}}{}{\mathrm{cos}}{}\left({x}\right){-}{19}{}{{x}}^{{2}}{}{{\mathrm{cos}}{}\left({x}\right)}^{{3}}{+}{62}{}{{\mathrm{sin}}{}\left({x}\right)}^{{4}}{}{\mathrm{cos}}{}\left({x}\right){+}{37}{}{\mathrm{sin}}{}\left({x}\right){}{{\mathrm{cos}}{}\left({x}\right)}^{{4}}$ (7)
 > $\mathrm{randpoly}\left(z,\mathrm{expons}=\mathrm{rand}\left(-5..5\right)\right)$
 $\frac{{86}}{{{z}}^{{2}}}{+}{64}{}{{z}}^{{4}}{-}\frac{{73}}{{{z}}^{{4}}}$ (8)
 > randpoly([x], coeffs = proc() randpoly(y) end proc);
 $\left({71}{}{{y}}^{{5}}{-}{47}{}{{y}}^{{4}}{-}{39}{}{{y}}^{{3}}{-}{53}{}{{y}}^{{2}}{-}{72}{}{y}{-}{97}\right){}{{x}}^{{5}}{+}\left({33}{}{{y}}^{{5}}{+}{10}{}{{y}}^{{4}}{+}{7}{}{{y}}^{{3}}{-}{89}{}{{y}}^{{2}}{+}{65}{}{y}{+}{12}\right){}{{x}}^{{4}}{+}\left({-}{25}{}{{y}}^{{5}}{-}{96}{}{{y}}^{{4}}{+}{50}{}{{y}}^{{3}}{-}{60}{}{{y}}^{{2}}{-}{42}{}{y}{+}{7}\right){}{{x}}^{{3}}{+}\left({-}{89}{}{{y}}^{{5}}{-}{70}{}{{y}}^{{4}}{+}{34}{}{{y}}^{{3}}{-}{68}{}{{y}}^{{2}}{-}{60}{}{y}{+}{16}\right){}{{x}}^{{2}}{+}\left({52}{}{{y}}^{{5}}{-}{20}{}{{y}}^{{4}}{-}{4}{}{{y}}^{{3}}{-}{89}{}{{y}}^{{2}}{-}{77}{}{y}{+}{69}\right){}{x}{+}{80}{}{{y}}^{{5}}{+}{28}{}{{y}}^{{4}}{-}{42}{}{{y}}^{{3}}{-}{33}{}{{y}}^{{2}}{+}{21}{}{y}{-}{35}$ (9)
 > $\mathrm{RandomTools}\left[\mathrm{Generate}\right]\left(\mathrm{polynom}\left(\mathrm{integer}\left(\mathrm{range}=-10..10\right),x,\mathrm{degree}=4\right)\right)$
 ${6}{}{{x}}^{{4}}{+}{9}{}{{x}}^{{3}}{-}{7}{}{{x}}^{{2}}{-}{9}{}{x}{-}{6}$ (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.

 > $\mathrm{randpoly}\left(x,\mathrm{coeffs}=\mathrm{rand}\left(-1..1\right),\mathrm{terms}=100\right)$
 ${{x}}^{{5}}{+}{{x}}^{{3}}{-}{{x}}^{{2}}{+}{x}{+}{1}$ (11)
 > $\mathrm{randpoly}\left(x,\mathrm{coeffs}=\mathrm{rand}\left(-1..1\right),\mathrm{expons}=\mathrm{rand}\left(2\right),\mathrm{terms}=100\right)$
 ${-}{14}{-}{5}{}{x}$ (12)