Contents Previous Next Index

11 Input, Output, and Interacting with Other Products



11.1 In This Chapter


Section

Topics

Writing to Files  Saving to Maple file formats

•

Saving Expressions to a File


Reading from Files Opening Maple files

•

Reading Data from a File

•

Reading Expressions from a File


Exporting to Other Formats  Exporting documents in file formats supported by other software


Connectivity  Using Maple with other programming languages and software

•

Translating Maple Code to Other Programming Languages

•

Accessing External Products from Maple

•

Accessing Maple from External Products

•

Sharing and Storing Maple Worksheet Content with the MapleCloud^{TM}






11.2 Writing to Files


Maple supports file formats in addition to the standard .mw file format.
After using Maple to perform a computation, you can save the results to a file for later processing with Maple or another program.
Note: Make sure you have right access to the directory in order to execute the example in the following subsections.

Saving Data to a File


If the result of a Maple calculation is a long list or a large array of numbers, you can convert it to Matrix form and write the numbers to a file using the ExportMatrix command. This command writes columns of numerical data to a file, allowing you to import the numbers into another program. To convert a list or a list of lists to a Matrix, use the Matrix constructor. For more information, refer to the Matrix help page.
>

$L:=\[\begin{array}{ccccc}\mathrm{81}& \mathrm{98}& \mathrm{76}& \mathrm{4}& 29\\ \mathrm{38}& \mathrm{77}& \mathrm{72}& 27& 44\\ \mathrm{18}& 57& \mathrm{2}& 8& 92\\ 87& 27& \mathrm{32}& 69& \mathrm{31}\\ 33& \mathrm{93}& \mathrm{74}& 99& 67\end{array}\]\:$

>

$\mathrm{ExportMatrix}\left(''matrixdata.txt''\,L\right)\:$

If the data is a Vector or any object that can be converted to type Vector, use the ExportVector command. To convert lists to Vectors, use the Vector constructor. For more information, refer to the Vector help page.
>

$R\u2254\left[3\,3.1415\,65\,0\right]$

${R}{:=}\left[{3}{\,}{3.1415}{\,}{}{65}{\,}{0}\right]$
 (11.1) 
>

$V\u2254\mathrm{Vector}\left(R\right)$

>

$\mathrm{ExportVector}\left(''vectordata.txt''\,V\right)\:$

You can extend these routines to write more complicated data, such as complex numbers or symbolic expressions. For more information, refer to the ExportMatrix and ExportVector help pages.
For more information on matrices and vectors, see Linear Algebra.


Saving Expressions to a File


If you construct a complicated expression or procedure, you can save them for future use in Maple. If you save the expression or procedure in the Maple internal format, Maple can retrieve it more efficiently than from a document. Use the save command to write the expression to a .m file. For more information on Maple internal file formats, refer to the file help page.
>

$\mathrm{qbinomial}\u2254\left(n\,k\right)\to \frac{\prod _{i\=nk\+1}^{n}\phantom{\rule[0.0ex]{5.0px}{0.0ex}}\left(1{q}^{i}\right)}{\prod _{i\=1}^{k}\phantom{\rule[0.0ex]{5.0px}{0.0ex}}\left(1{q}^{i}\right)}\:$

In this example, small expressions are used. In practice, Maple supports expressions with thousands of terms.
>

$\mathrm{expr}\u2254\mathrm{qbinomial}\left(10\,4\right)$

${\mathrm{expr}}{:=}\frac{\left({1}{}{{q}}^{{7}}\right){}\left({1}{}{{q}}^{{8}}\right){}\left({1}{}{{q}}^{{9}}\right){}\left({1}{}{{q}}^{{10}}\right)}{\left({1}{}{q}\right){}\left({1}{}{{q}}^{{2}}\right){}\left({1}{}{{q}}^{{3}}\right){}\left({1}{}{{q}}^{{4}}\right)}$
 (11.2) 
>

$\mathrm{nexpr}\u2254\mathrm{normal}\left(\mathrm{expr}\right)$

${\mathrm{nexpr}}{:=}\left({{q}}^{{6}}{\+}{{q}}^{{5}}{\+}{{q}}^{{4}}{\+}{{q}}^{{3}}{\+}{{q}}^{{2}}{\+}{q}{\+}{1}\right){}\left({{q}}^{{4}}{\+}{1}\right){}\left({{q}}^{{6}}{\+}{{q}}^{{3}}{\+}{1}\right){}\left({{q}}^{{8}}{\+}{{q}}^{{6}}{\+}{{q}}^{{4}}{\+}{{q}}^{{2}}{\+}{1}\right)$
 (11.3) 
You can save these expressions to the file qbinom.m.
>

$\mathbf{save}\mathrm{qbinomial}comma;\mathrm{expr}comma;\mathrm{nexpr}comma;''qbinom.m''$

Clear the memory using the restart command and retrieve the expressions using the read command.
>

$\mathbf{read}''qbinom.m''$

$\frac{\left({1}{}{{q}}^{{7}}\right){}\left({1}{}{{q}}^{{8}}\right){}\left({1}{}{{q}}^{{9}}\right){}\left({1}{}{{q}}^{{10}}\right)}{\left({1}{}{q}\right){}\left({1}{}{{q}}^{{2}}\right){}\left({1}{}{{q}}^{{3}}\right){}\left({1}{}{{q}}^{{4}}\right)}$
 (11.4) 
For more information on writing to files, refer to the save help page.


Saving Data as Part of a Workbook


You can save all files related to a common Maple project as a workbook (.maple) file. Saving your data files and worksheets (or documents) as a workbook allows you to use this saved data across all .mw file inside your workbook.



11.3 Reading from Files


The most common reason for reading files is to load data, for example, data generated in an experiment. You can store data in a text file, and then read it into Maple.

Reading Data from a File



Import Data Assistant


If you generate data outside Maple, you can read it into Maple for further manipulation. This data can be an image, a sound file, or columns of numbers in a text file. You can easily import this external data into Maple using the Import Data Assistant, where the supported file formats include files of type Excel^{®}, MATLAB^{®}, Image, Audio, Matrix Market, and Delimited.
To launch the Import Data Assistant:
1.

From the Tools menu, select Assistants, and then Import Data.

2.

A dialog window appears where you can navigate to your data file. Select the file that you want to import data from, and then select the file type before clicking Next.

3.

From the main window, you can preview the selected file and choose from the applicable options based on the format of the file read in before importing the data into Maple. See Figure 11.1 for an example.


Figure 11.1: Import Data Assistant





ImportMatrix Command


The Import Data Assistant provides a graphical interface to the ImportMatrix command. For more information, including options not available in the assistant, refer to the ImportMatrix help page.



Reading Expressions from a File


You can write Maple programs in a text file using a text editor, and then import the file into Maple. You can paste the commands from the text file into your document or you can use the read command.
When you read a file with the read command, Maple treats each line in the file as a command. Maple executes the commands and displays the results in your document but it does not, by default, insert the commands from the file in your document.
For example, the file ks.txt contains the following Maple commands.
S:= n > sum( binomial( n, beta ) * ( ( 2*beta )! / 2^beta  beta!*beta ), beta=1..n );
S(19);
Note that the file should not contain prompts (>) at the start of lines.
When you read the file, Maple displays the results but not the commands.
${S}{:=}{n}{\→}{\sum}_{{\mathrm{\β}}{\=}{1}}^{{n}}\phantom{\rule[0.0ex]{5.0px}{0.0ex}}{\mathrm{binomial}}\left({n}{\,}{\mathrm{\β}}\right){}\left(\frac{\left({2}{}{\mathrm{\β}}\right){\!}}{{{2}}^{{\mathrm{\β}}}}{}{\mathrm{\β}}{\!}{}{\mathrm{\β}}\right)$
 
${1024937361666644598071114328769317982974}$
 (11.5) 
>

$\mathrm{filename}\u2254\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right)\,\mathrm{kernelopts}\left(\mathrm{dirsep}\right)\,''ks''\,\mathrm{kernelopts}\left(\mathrm{dirsep}\right)comma;''ks.txt''\right)colon;$

>

$\mathbf{read}\mathrm{filename}$

${S}{:=}{n}{\→}{\sum}_{{\mathrm{\β}}{\=}{1}}^{{n}}\phantom{\rule[0.0ex]{5.0px}{0.0ex}}{\mathrm{binomial}}\left({n}{\,}{\mathrm{\β}}\right){}\left(\frac{\left({2}{}{\mathrm{\β}}\right){\!}}{{{2}}^{{\mathrm{\β}}}}{}{\mathrm{\β}}{\!}{}{\mathrm{\β}}\right)$
 
${1024937361666644598071114328769317982974}$
 (11.6) 
If you set the interface echo option to 2, Maple inserts the commands from the file into your document.
>

$\mathrm{interface}\left(\mathrm{echo}\=2\right)\:\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\mathbf{read}\mathrm{filename}$

> S:= n > sum( binomial( n, beta ) * ( ( 2*beta )! / 2^beta  beta!*beta ), beta=1..n );
 
${S}{:=}{n}{\→}{\sum}_{{\mathrm{\β}}{\=}{1}}^{{n}}\phantom{\rule[0.0ex]{5.0px}{0.0ex}}{\mathrm{binomial}}\left({n}{\,}{\mathrm{\β}}\right){}\left(\frac{\left({2}{}{\mathrm{\β}}\right){\!}}{{{2}}^{{\mathrm{\β}}}}{}{\mathrm{\β}}{\!}{}{\mathrm{\β}}\right)$
 
${1024937361666644598071114328769317982974}$
 (11.7) 
For more information, refer to the read and interface help pages.


Reading Data From Workbook Attachments


Data stored in a workbook in the form of an attachment, can be accessed easily using the workbook URI. For information on workbook attachments, see worksheet,workbook,attachFiles. For information on the workbook URI format, see worksheet,workbook,uri.



11.4 Exporting to Other Formats



Exporting Documents


You can save your documents by selecting Save or Save As from the File menu. By selecting Export As from the File menu, you can also export a document in the following formats: HTML, LaTeX, Maple input, Maplet application, Maple text, plain text, PDF, and Rich Text Format. This allows you to access your work outside Maple.

HTML


The .html file that Maple generates can be loaded into any HTML browser. Exported mathematical content can be displayed in one of two formats, GIF or MathML 2.0, and is saved in a separate folder. MathML is the Internet standard, sanctioned by the World Wide Web Consortium (W3C), for the communication of structured mathematical formulae between applications. For more information about MathML, refer to the MathML help page.
Maple documents that are exported to HTML translate into multiple documents when using frames. If the frames feature is not selected, Maple creates only one page that contains the document contents.


LaTeX


The .tex file generated by Maple is ready for processing by LaTeX. All distributions of Maple include the necessary style files. By default, the LaTeX style files are set for printing the .tex file using the dvips printer driver. You can change this behavior by specifying an option to the \usepackage LaTeX command in the preamble of your .tex file. For more information, refer to the exporttoLaTeX help page.


Maple Input


You can export a Maple document as Maple input so that it can be loaded using the Maple Commandline version.
Important: When exporting a document as Maple input for use in Commandline Maple, your document must contain explicit semicolons in 1D Math input. If not, the exported .mpl file does not contain semicolons, and Commandline Maple generates errors.


Maplet Application


The Export as Maplet facility saves a Maple document as a .maplet file, so that you can run it using the commandline interface or the MapletViewer. The MapletViewer is an executable program that can launch saved Maplet applications. It displays and runs Maplet applications independently of the Maple Worksheet interface.
Important: When exporting a document as a Maplet Application for use in Commandline Maple or the MapletViewer, your document must contain explicit semicolons. If not, the exported .maplet file does not contain semicolons, and Commandline Maple and the MapletViewer generates errors.


Maple Text


Maple text is marked text that retains the distinction between text, Maple input, and Maple output. Thus, you can export a document as Maple text, send the text file by email, and the recipient can import the Maple text into a Maple session and regenerate the computations in the original document.


PDF


Export a Maple document to a Portable Document Format (PDF) file so that you can open the file in a reader such as Adobe^{®} Acrobat^{®}. The PDF document is formatted as it would appear when the Maple worksheet is printed using the active printer settings.
Note: Images, plots, and embedded components may be resized in the PDF file.


Plain Text


Export a Maple document as plain text so that you can open the text file in a word processor.


Rich Text Format (RTF)


Export a Maple document to a rich text format file so that you can open and edit the file in a word processor.
Note: The generated .rtf format is compatible with Microsoft Word and Microsoft WordPad only.


Summary of Translation


Table 11.1: Summary of Content Translation When Exporting to Different Formats 
Content

HTML

LaTeX

Maple Input

Maplet Application

Maple Text

Plain Text

Rich Text Format

PDF Format

Text

Maintained

Maintained

Preceded by #

Preceded by #

Preceded by #

Maintained

Maintained

Maintained

1D Math

Maintained

Maintained

Maintained

Maintained

Preceded by >

Preceded by >

Static image

Static image

2D Math

GIF or MathML

LaTeX

1D Math (if possible)

1D Math (if possible)

1D Math or characterbased typesetting

1D Math or characterbased typesetting

Static image

Either text or shapes depending on option selected

Plot

GIF

Postscript file

Not exported

Not exported

Not exported

Not exported

Static image

Static image

Animation

Animated GIF

Not exported

Not exported

Not exported

Not exported

Not exported

Not exported

Static image

Hidden content

Not exported

Not exported

Not exported

Not exported

Not exported

Not exported

Not exported

Not exported

Manually inserted page break

Not supported

Not supported

Not supported

Not supported

Not supported

Not supported

RTF page break object

Maintained

Hyperlink

Links to help pages become plain text. Links to documents are renamed and converted to HTML links

Plain text

Plain text

Plain text

Plain text

Plain text

Plain text

Plain text

Embedded image or sketch output

GIF

Not exported

Not exported

Not exported

Not exported

Not exported

Static image

Static image

Spreadsheet

HTML table

LaTeX tables

Not exported

Not exported

Not exported

Not exported

RTF table

Static image

Document style

Approximated by HTML style attributes

LaTeX environments and sections, LaTeX macro calls

Not exported

Not exported

Not exported

Not exported

RTF style

Maintained





MapleNet



Overview of MapleNet



Using MapleNet, you can deploy Maple content on the web. Powered by the Maple computation engine, MapleNet allows you to embed dynamic formulas, models, and diagrams as live content in webpages. The MapleNet software is not included with the Maple software. For more information on MapleNet, visit http://www.maplesoft.com/maplenet.



MapleNet Documents and Maplets


After you upload your Maple document to the MapleNet server, it can be accessed by anyone in the world using a web browser. Even if viewers do not have a copy of Maple installed, they can view documents and Maplets, manipulate 3D plots, and execute code at the click of a button.


Custom Java Applets and JavaServer Pages^{TM} Technology


MapleNet provides a programming interface to the Maple math engine so commands can be executed from a Java applet or using JavaServer Pages^{TM} technology. Embed MapleNet into your web application, and let Maple handle the math and visualization.




11.5 Connectivity



Translating Maple Code To Other Programming Languages



Code Generation


The CodeGeneration package is a collection of commands and subpackages that enable the translation of Maple code to other programming languages. Languages currently supported include: C, C#, Fortran 77, Java, MATLAB^{®}, Visual Basic, Perl, and Python.
For details on Code Generation, refer to the CodeGeneration help page.



Accessing External Products from Maple



External Calling


External calling allows you to use compiled C, C#, Fortran 77, or Java code in Maple. Functions written in these languages can be linked and used as if they were Maple procedures. With external calling you can use prewritten optimized algorithms without the need to translate them into Maple commands. Access to the NAG library routines and other numerical algorithms is built into Maple using the external calling mechanism.
External calling can also be applied to functions other than numerical algorithms. Routines exist that accomplish a variety of nonmathematical tasks. You can use these routines in Maple to extend its functionality. For example, you can link to controlled hardware via a serial port or interface with another program. The Database package uses external calling to allow you to query, create, and update databases in Maple. For more information, refer to the Database help page.
For more information on using external calling, refer to the ExternalCalling help page.


Mathematica Translator


The MmaTranslator package provides translation tools for converting Mathematica^{®} expressions, command operations, and notebooks to Maple. The package can translate Mathematica input to Maple input and Mathematica notebooks to Maple documents. The Mma subpackage contains commands that provide translation for Mathematica commands when no equivalent Maple command exists. In most cases, the command achieves the translation through minor manipulations of the input and output of similar Maple commands.
Note: The MmaTranslator package does not convert Mathematica programs.
There is a Maplet interface to the MmaTranslator package. For more information, refer to the MmaToMaple help page.


Matlab Package


The Matlab package enables you to translate MATLAB^{®} code to Maple, as well as call selected MATLAB^{®} functions from a Maple session, provided you have MATLAB^{®} installed on your system.
For more information, refer to the Matlab help page.



Accessing Maple from External Products



Microsoft Excel AddIn


Maple is available as an addin to Microsoft Excel. This addin is supported for Excel 2019 and Excel 2016 for Windows, and provides the following features.
•

Access to Maple commands from Excel

•

Ability to copy and paste between Maple and Excel

•

Access to a subset of the Maple help pages

•

Maple Function Wizard to step you through the creation of a Maple function call

To enable the Maple Excel Addin:
1.

In Excel, click the File menu and select Options.

3.

In the Manage box select Excel Addins, and then Go.

4.

Navigate to the Excel subdirectory of your Maple installation and select the file:

–

WMIMPLEX64.xla (that is, select $MAPLE/Excel/WMIMPLEX64.xla), and click OK.

5.

Select the Maple Excel Addin check box.

For further details on enabling the Maple Excel Addin, refer to the Excel help page.
For information on using this addin, refer to the Using Maple in Excel help file within Excel.
To view this help file:
2.

From the Addins tab, view the Maple toolbar.

3.

On the Maple toolbar, click the Maple help icon
.



OpenMaple


OpenMaple is a suite of functions that allows you to access Maple algorithms and data structures in your compiled C, C#, Java, or Visual Basic programs. (This is the reverse of external calling, which allows access to compiled C, C#, Fortran 77, and Java code from Maple.)
To run your application, Maple must be installed. You can distribute your application to any licensed Maple user. For additional terms and conditions on the use of OpenMaple, refer to the extern/OpenMapleLicensing.txt file in your Maple installation.
For more details on using OpenMaple functions, refer to the OpenMaple help page.


MapleSim


MapleSim^{TM} is a complete environment for modeling and simulating multidomain engineering systems. During a simulation, MapleSim uses the symbolic Maple computation engine to generate the mathematical models that represent the system behavior.
Because both products are tightly integrated, you can use Maple commands and technical document features to edit, manipulate, and analyze a MapleSim model. For example, you can use Maple commands and tools to manipulate your model equations, develop custom components based on a mathematical model, and visualize simulation results.
MapleSim software is not included with the Maple software. For more information on MapleSim, visit http://www.maplesoft.com/maplesim.


MaplePlayer for iPad


The Maple Player is a free application for the iPad that uses the Maple computation engine to enable you to view and interact with documents created in desktop Maple.
For more information on the Maple Player for iPad, visit http://www.maplesoft.com/products/MaplePlayer.



Sharing and Storing Maple Content



The MapleCloud


You can use the MapleCloud to share or store your Maple documents and workbooks. Upload Maple documents or workbooks. Package workbooks offer a way to share a Maple package with other users, including source code, documentation and examples.
The MapleCloud has private and public sharing. You can share with all Maple users, share with a private group, or upload and store content in a userspecific area that only you can access.
Users need an internet connection to use the MapleCloud. Anyone can access publicly shared documents. To share content, create, manage and join user groups; and view groupspecific content, you must log in to the MapleCloud using a Maplesoft.com, Gmail™, or Google Mail™ account name and password.
A Maplesoft.com membership account gives you access to thousands of free Maple resources and MaplePrimes, which is an active web community for sharing techniques and experiences with Maple and related products. To sign up for a free Maplesoft.com membership account, visit http://www.maplesoft.com/members/sign_up_form.aspx. The MapleCloud is integrated with several of these online features, so it is strongly recommended that you use a Maplesoft.com membership account.
For more information on the MapleCloud, refer to the MapleCloud help page.




Contents Previous Next Index
