Symbolic Math Toolbox | ![]() ![]() |
Vectorized Example
Suppose we want to calculate the sine of a symbolic matrix. One way to do this is
A more efficient way to do this is to call Maple just once, using the Maple map
function. The map
function applies a Maple function to each element of an array. In our sine calculation example, this looks like
function y = sin2(x) if prod(size(x)) == 1 % scalar case y = maple('sin',x); else % array case y = maple('map','sin',x); end
Note that our sin2
function treats scalar and array cases differently. It applies the map
function to arrays but not to scalars. This is because map
applies a function to each operand of a scalar.
Because our sin2
function calls Maple only once, it is considerably faster than our sin1
function, which calls Maple prod(size(A))
number of times.
The map
function can also be used for Maple functions that require multiple input arguments. In this case, the syntax is
For example, one way to call the collect
M-file is collect(S,x)
. In this case, the collect
function collects all the coefficients with the same power of x
for each element in S
. The core section of the implementation is shown below.
For additional information on the Maple map
function, type
![]() | Simple Example | Debugging | ![]() |