Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mapcoeffs

Apply a function to the coefficients of a 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.

Syntax

mapcoeffs(p, F, <a1, a2, …>)
mapcoeffs(f, <vars>, F, <a1, a2, …>)

Description

mapcoeffs(p, F, a1, a2, ...) applies the function F to the polynomial p by replacing each coefficient c in p by F(c, a1, a2, ...).

For a polynomial p of type DOM_POLY generated by poly, the function F must accept arguments from the coefficient ring of p and must produce corresponding results.

A polynomial expression f is first converted to a polynomial with the variables given by vars. If no variables are given, they are searched for in f. See poly about details of the conversion. FAIL is returned if f cannot be converted to a polynomial. After applying the function F, the result is converted to an expression.

mapcoeffs evaluates its arguments. Note, however, that polynomials of type DOM_POLY do not evaluate their coefficients for efficiency reasons. Cf. Example 4.

Examples

Example 1

The function sin is mapped to the coefficients of a polynomial expression in the indeterminates x and y:

mapcoeffs(3*x^3 + x^2*y^2 + 2, sin)

The following call makes mapcoeffs regard this expression as a polynomial in x. Consequently, y is regarded as a parameter that becomes part of the coefficients:

mapcoeffs(3*x^3 + x^2*y^2 + 2, [x], sin)

The system function _plus adds its arguments. In the following call, it is used to add 2 to all coefficients by providing this shift as an additional argument:

mapcoeffs(c1*x^3 + c2*x^2*y^2 + c3, [x, y], _plus, 2)

Example 2

The function sin is mapped to the coefficients of a polynomial in the indeterminates x and y:

mapcoeffs(poly(3*x^3 + x^2*y^2 + 2, [x, y]), sin)

In the following call, the polynomial has the indeterminate x. Consequently, y is regarded as a parameter that becomes part of the coefficients:

mapcoeffs(poly(3*x^3 + x^2*y^2 + 2, [x]), sin)

A user-defined function is mapped to a polynomial:

F := (c, a1, a2) -> exp(c + a1 + a2): 
mapcoeffs(poly(x^3 + c*x, [x]), F, a1, a2)

delete F:

Example 3

We consider a polynomial over the integers modulo 7:

p := poly(x^3 + 2*x*y, [x, y], Dom::IntegerMod(7)):

A function to be applied to the coefficients must produce values in the coefficient ring of the polynomial:

mapcoeffs(p, c -> c^2)

The following call maps a function which converts its argument to an integer modulo 3. Such a return value is not a valid coefficient of p:

mapcoeffs(p, c -> Dom::IntegerMod(3)(expr(c)))

delete p:

Example 4

Note that polynomials of type DOM_POLY do not evaluate their arguments:

delete a, x: p := poly(a*x, [x]): a := PI: p

Evaluation can be enforced by the function eval:

mapcoeffs(p, eval)

We map the sine function to the coefficients of p. The polynomial does not evaluate its coefficient sin(a) to 0:

mapcoeffs(p, sin)

The composition of sin and eval is mapped to the coefficients of the polynomial:

mapcoeffs(p, eval@sin)

delete p, a:

Parameters

p

A polynomial of type DOM_POLY

F

A procedure

a1, a2, …

Additional parameters for the function F

f

A polynomial expression

vars

A list of indeterminates of the polynomial: typically, identifiers or indexed identifiers

Return Values

Polynomial of type DOM_POLY, or a polynomial expression, or FAIL.

Overloaded By

f, p

See Also

MuPAD Functions

Was this topic helpful?