Overview of the Matlab Package - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Packages : Matlab

Overview of the Matlab Package

 

Calling Sequence

Description

List of Matlab Package Commands

Examples

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.

AddTranslator

chol

closelink

defined

det

dimensions

eig

evalM

fft

FromMatlab

FromMFile

getvar

inv

lu

ode15s

ode45

openlink

qr

setup

setvar

size

square

transpose

 

  

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].

withMatlab:

Generate some data for analysis.

num1500:

Timeseq0.03t,t=1..num:

dataseq3.6cosTimet+cos6Timet,t=1..num:

plots[pointplot]zipx,y→x,y,Time,data,style=line

Add noise to the data.

tol10000:

rrand0..tol:

noisy_dataseqrdatattol,t=1..num:

plots[pointplot]zipx,y→x,y,Time,noisy_data,style=line

Use MATLAB® to calculate the Fourier Transform.

ftfftnoisy_data:

Check whether this is a complex Vector.

VectorOptionsft,datatype

Split it into parts.

real_partmapℜ,ft:

imag_partmapℑ,ft:

How big is the returned value?

dimensionsft

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.

setvarFT,ft

setvarn,num

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

evalMresult = FT.*conj(FT)/n

Get the result.

pwrgetvarresult:

Note that this result is not complex.

VectorOptionspwr,datatype

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

pwr_listconvertpwr,list:

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

pwr_pointsseqt1Timenum,pwr_listt,t=1..num2:

plots[pointplot]pwr_points,style=line

There are two obvious frequencies. The dominant frequency is:

pwr1maxoppwr_list

i1seq`if`pwr_pointst,2=pwr1,t,NULL,t=1..nopspwr_points

f1pwr_pointsi1,1

So the period is:

T11f1

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

pwr2maxseqpwr_listt,t=i1+5..num2

i2seq`if`pwr_pointst,2=pwr2,t,NULL,t=1..nopspwr_points

f2pwr_pointsi2,1

So the secondary period is:

T21f2

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

See Also

Configuring a Computer for MATLAB(R)

Matlab[closelink]

Matlab[evalM]

Matlab[getvar]

Matlab[openlink]

Matlab[setvar]

trademark

UsingPackages

with

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam