Overview - Maple Help

Overview of the Matlab Package

 Calling Sequence Matlab[command](arguments) command(arguments)

Description

 • The Matlab package contains commands that communicate with MATLAB® and commands that translate MATLAB® code to Maple.
 • Primary Matlab communication functions are Matlab[evalM], Matlab[getvar], and Matlab[setvar].  Related communications infrastructure commands also include Matlab[defined], Matlab[openlink], and Matlab[closelink]. A properly configured MATLAB® installation is required to run these commands.
 Secondary commands that use a connection to MATLAB® to evaluate domain specific functions in the MATLAB® environment include: Matlab[chol], Matlab[det], Matlab[dimensions], Matlab[eig], Matlab[fft], Matlab[inv], Matlab[lu], Matlab[ode15s], Matlab[ode45], Matlab[qr], Matlab[size], Matlab[square], and Matlab[transpose]. These are all built on the primary commands and simply move data back and forth between MATLAB® and Maple in order to evaluate a specific MATLAB® command. A properly configured MATLAB® installation is required to run these commands.
 The Matlab package also contains commands that translate MATLAB® code into Maple.  Refer to Matlab[FromMatlab], Matlab[FromMFile] and Matlab[AddTranslator].  These translation commands are entirely built within Maple and do not require MATLAB® to execute. The rest of this help page is not relevant to the translation commands.
 • To successfully invoke any command that requires communication with MATLAB® you must be on a platform that supports an identical MATLAB® architecture, and have a licensed MATLAB® executable in the path. For details, see Configuring a Computer for MATLAB(R).
 • Commands that communicate with MATLAB® via the Matlab package in Maple are collectively referred to as the "Matlab Link."  Communication is initiated by Maple to evaluate commands in MATLAB® and possibly return a result.  The reverse situation, where communication is initiated by MATLAB® to evaluate commands using Maple's computation engine is available via an add-on toolbox, "The Maple Toolbox". For details, see Maple Toolbox Installation.
 • When communicating with MATLAB®, it is important to understand the difference between the following two types of matrices, both of which can be used in Matlab command calls.
 (1) MatlabMatrix - Strings usually denote the name of a variable defined in MATLAB®. For example, the command Matlab[inv]("M") computes the inverse of the variable, M, which is defined in MATLAB®. If a variable M is also defined in Maple, the stated call will not affect it.  The two calls, Matlab[det](M) and Matlab[det]("M") are very different.
 (2) MapleMatrix - A MapleMatrix is any Maple expression that is equivalent to a fully defined Maple matrix; do not confuse MapleMatrix with the "matrix" type in Maple. A MapleMatrix can be an rtable (Array, Matrix or Vector), a table, or a constant (numeric or complex numeric or a symbolic constant such as Pi or infinity). All elements of the MapleMatrix must be of type constant.
 • Constants in Maple are represented as 1x1 matrices in MATLAB®. Command calls such as Matlab[det](543) are acceptable. Conversely, 1x1 matrices returned from MATLAB® are converted back to constants in Maple.  This creates a special case when a Maple user actually wants a 1x1 matrix returned.
 • Most Matlab commands that have a return value return a constant or an rtable (that is, Array, Matrix, or Vector) with a hardware datatype (float[8] or complex[8]). The exceptions are Matlab[size] and Matlab[dimensions], which both return integer lists.
 • To compute intermediate steps in evaluation, Maple uses several MATLAB® variables.  The names of these variables are prefixed by "result_for_maple"; for example, result_for_maple_1, result_for_maple_2, and so on.
 • Since conversion from non-fully defined (table-based) arrays (matrices, vectors) to (rtable-based) Arrays (Matrices, Vectors) replaces the undefined elements with zeros, Matlab[setvar]() does this also.  For example, Matlab[setvar]("x", array(1..2, [])); sets x=[0 0] in MATLAB®.
 • One-dimensional objects are treated as row or column vectors by MATLAB®, consistent with the Maple prettyprinter.
 • Note to Windows users: Maple opens only one MATLAB® session. This ensures that any MATLAB® variables defined in Maple apply to all worksheets in a session, even if you are running parallel server Maple.
 • Each command in the Matlab package can be accessed by using either the long form or the short form of the command name in the command calling sequence.

List of Matlab Package Commands

 • The following is a list of available commands.

 To display the help page for a particular Matlab command, see Getting Help with a Command in a Package.

Examples

To see the output from the examples, copy the examples to a worksheet and execute the worksheet. For information on accessing MATLAB® from Maple, see Matlab[setup].

 > $\mathrm{with}\left(\mathrm{Matlab}\right):$

Generate some data for analysis.

 > $\mathrm{num}≔1500:$
 > $\mathrm{times}≔\left[\mathrm{seq}\left(0.03t,t=1..\mathrm{num}\right)\right]:$
 > $\mathrm{data}≔\left[\mathrm{seq}\left(3.6\mathrm{cos}\left(\mathrm{times}\left[t\right]\right)+\mathrm{cos}\left(6\mathrm{times}\left[t\right]\right),t=1..\mathrm{num}\right)\right]:$
 > $\mathrm{plots}\left[\mathrm{pointplot}\right]\left(\mathrm{zip}\left(\left(x,y\right)↦\left[x,y\right],\mathrm{times},\mathrm{data}\right),\mathrm{style}=\mathrm{line}\right)$

 > $\mathrm{tol}≔10000:$
 > $r≔\mathrm{rand}\left(0..\mathrm{tol}\right):$
 > $\mathrm{noisy_data}≔\left[\mathrm{seq}\left(\frac{r\left(\right)}{\mathrm{tol}}\mathrm{data}\left[t\right],t=1..\mathrm{num}\right)\right]:$
 > $\mathrm{plots}\left[\mathrm{pointplot}\right]\left(\mathrm{zip}\left(\left(x,y\right)↦\left[x,y\right],\mathrm{times},\mathrm{noisy_data}\right),\mathrm{style}=\mathrm{line}\right)$

Use MATLAB® to calculate the Fourier Transform.

 > $\mathrm{ft}≔\mathrm{fft}\left(\mathrm{noisy_data}\right):$

Check whether this is a complex Vector.

 > $\mathrm{VectorOptions}\left(\mathrm{ft},\mathrm{datatype}\right)$

Split it into parts.

 > $\mathrm{real_part}≔\mathrm{map}\left(\mathrm{\Re },\mathrm{ft}\right):$
 > $\mathrm{imag_part}≔\mathrm{map}\left(\mathrm{\Im },\mathrm{ft}\right):$

How big is the returned value?

 > $\mathrm{dimensions}\left(\mathrm{ft}\right)$

The length is the same as the defined variable 'num' .

To calculate the power spectrum, you need ft * conj(ft) /n. To do this in MATLAB®, first put 'ft' into the MATLAB® memory.

 > $\mathrm{setvar}\left("FT",\mathrm{ft}\right)$
 > $\mathrm{setvar}\left("n",\mathrm{num}\right)$

Calculate the desired result with evalM, ensuring the result is assigned to a variable so that the Matlab[getvar] command can be used.

 > $\mathrm{evalM}\left("result = FT.*conj\left(FT\right)/n"\right)$

Get the result.

 > $\mathrm{pwr}≔\mathrm{getvar}\left("result"\right):$

Note that this result is not complex.

 > $\mathrm{VectorOptions}\left(\mathrm{pwr},\mathrm{datatype}\right)$

Plot the power spectrum. You must convert 'pwr' to a list in this case.

 > $\mathrm{pwr_list}≔\mathrm{convert}\left(\mathrm{pwr},\mathrm{list}\right):$

Due to symmetry, you must plot only the first half of the values.

 > $\mathrm{pwr_points}≔\left[\mathrm{seq}\left(\left[\frac{t-1}{\mathrm{times}\left[\mathrm{num}\right]},\mathrm{pwr_list}\left[t\right]\right],t=1..\frac{\mathrm{num}}{2}\right)\right]:$
 > $\mathrm{plots}\left[\mathrm{pointplot}\right]\left(\mathrm{pwr_points},\mathrm{style}=\mathrm{line}\right)$

There are two obvious frequencies. The dominant frequency is:

 > $\mathrm{pwr1}≔\mathrm{max}\left(\mathrm{op}\left(\mathrm{pwr_list}\right)\right)$
 > $\mathrm{i1}≔\mathrm{seq}\left(\mathrm{if}\left(\mathrm{pwr_points}\left[t,2\right]=\mathrm{pwr1},t,\mathrm{NULL}\right),t=1..\mathrm{nops}\left(\mathrm{pwr_points}\right)\right)$
 > $\mathrm{f1}≔\mathrm{pwr_points}\left[\mathrm{i1},1\right]$

So the period is:

 > $\mathrm{T1}≔\frac{1}{\mathrm{f1}}$

Find the secondary frequency. From the plot, you see that it is past t1.

 > $\mathrm{pwr2}≔\mathrm{max}\left(\mathrm{seq}\left(\mathrm{pwr_list}\left[t\right],t=\mathrm{i1}+5..\frac{\mathrm{num}}{2}\right)\right)$
 > $\mathrm{i2}≔\mathrm{seq}\left(\mathrm{if}\left(\mathrm{pwr_points}\left[t,2\right]=\mathrm{pwr2},t,\mathrm{NULL}\right),t=1..\mathrm{nops}\left(\mathrm{pwr_points}\right)\right)$
 > $\mathrm{f2}≔\mathrm{pwr_points}\left[\mathrm{i2},1\right]$

So the secondary period is:

 > $\mathrm{T2}≔\frac{1}{\mathrm{f2}}$

Note that T1 and T2 are close to the angle multipliers in the original equation, which is expected.