11.3 Maple

 < Day Day Up > 



11.3 Maple

Maple is, like Mathematica, a general-purpose technical computing package that offers support for numerical and symbolic calculations, graphics, data analysis, and programming. The main difference is that Maple's front end is not as flexible and configurable as Mathematica's. Maple does not include as much support for document processing and typesetting, such as the ability to edit the expression structure of mathematical notation or to create programmable documents. Maple is available for Windows and most Unix platforms but not for Macintosh.

The Maple Interface

The native file format in Maple is called a worksheet. When you first launch Maple, a new worksheet that shows a command prompt (>) enclosed in an execution group appears. Each execution group is indicated by a square bracket on the left of the worksheet and contains a group of input commands that are to be evaluated as a group. To get a new execution group with a command prompt, choose Insert Execution Group After Cursor.

Doing Calculations

To do a calculation, you type a command followed by a semicolon after the command prompt, and then press Enter to evaluate the input. The result of the calculation is returned as output immediately below the input. A typical Maple command consists of a Maple function name followed by one or more arguments for the function enclosed in parentheses. All function names start with a lowercase letter. Here is an example of a Maple command:

    int(sin(x), x=0..Pi); 

Here, int and sin are Maple functions that represent the integration and the sine function, respectively. Pressing Enter causes Maple to evaluate the command, and the resulting output is printed just below the input. Figure 11.8 shows an example of Maple input and output in a worksheet.

click to expand
Figure 11.8: The Maple interface showing a worksheet, toolbars, and palettes..

Entering Mathematical Notation

You can enter input for evaluation in two forms:

  • Maple input: consists of plain-text commands written in a Maple-specific syntax

  • Standard mathematical notation-: simulates the two-dimensional layout of traditional mathematical notation

To enter input in Maple syntax, choose Insert Maple Input. When you are in Maple input mode, any text you type appears directly in the worksheet after the command prompt.

Figure 11.9 shows an example of Maple input in an execution group, with the corresponding output displayed below it.

click to expand
Figure 11.9: A worksheet that shows the result of evaluating a command in Maple input.

You can toggle between Maple input and standard mathematical notation by clicking the x button in the toolbar at the top of the application window. For example, you can use this button to convert the Maple input of Figure 11.9 into standard mathematical notation, shown in Figure 11.10.

click to expand
Figure 11.10: The same input as in Figure 11.9 shown in standard mathematical notation instead of Maple input.

To directly enter executable input in standard mathematical notation, choose Insert Standard Math Input. When you are in this mode, a question mark (?) appears in the input area, and a text editing window appears at the top of the screen. Any text you type first appears in this editing window. If you then press Enter, the text in the editing window is copied into the worksheet at the position of the ? sign.

Figure 11.11 shows the Insert menu, which contains commands for entering text, standard mathematical notation, and Maple input and standard mathematical input.


Figure 11.11: The Maple Insert menu, which shows the different types of input formats.

You can then construct the mathematical notation you want using the templates from the Expression palette as building blocks. The Expression palette contains buttons for entering most of the standard types of mathematical notation, such as subscripts, superscripts, fractions, square roots, or integrals. There are also separate palettes for entering vectors, matrices, and symbols such as Greek characters.

If you press any of the buttons on the Expression palette, a template for the corresponding notation appears in the worksheet, with the different parts of the template indicated by ? signs. You can move between the different ? positions by pressing Tab.

Entering Text and Inline Equations

You can intersperse text with the input and output by creating text areas. To enter text, choose Insert Text or click the T button in the toolbar. Any text you type then appears in a text region of the worksheet. You can format paragraphs in a specific style (such as that of a heading, subheading, or normal text) by choosing one of the predefined styles from the Format Style menu. By combining text in specific styles with execution groups that contain input-output pairs, you can create nicely formatted technical documents.

You can include mathematical notation in a text cell in the form of inline equations (Figure 11.12). To do this in a text region, choose Insert Standard Math or click Σ in the tool bar. This inserts a ? sign at the position of the cursor. You can type in the notation in the text box at the top of the document and then press Enter for the corresponding notation to be inserted into the text cell to replace the ? sign.

click to expand
Figure 11.12: Entering an inline equation in a text region using the Expression palette.

Copying and Pasting MathML

Version 7 and later versions of Maple include full support for MathML 2.0. Both presentation and content tags are supported. You can import, evaluate, and export MathML functions using either copying and pasting, menu commands, or specialized package functions.

To copy mathematical output as MathML, follow these steps:

  1. Select the expression you wish to convert into MathML in the Maple worksheet.

  2. Right-click with the mouse. This brings up a contextual menu of the type shown in Figure 11.13.

    click to expand
    Figure 11.13: The contextual menu for converting output into MathML.

  3. From the menu choose Conversions MathML.

A MathML version of the selected expression is returned as an output string. You can then copy the MathML expression from the output and paste it into another application.

You can also copy MathML equations from another application and paste them into Maple in the form of a valid Maple expression. When you attempt to paste a MathML expression into a worksheet, you will get a dialog that asks if you wish to interpret the expression or paste it literally (Figure 11.14). If you click Yes, the corresponding Maple expression will be pasted into the worksheet.

click to expand
Figure 11.14: The dialog that appears when you paste a MathML expression into a worksheet.

Exporting a Worksheet As HTML+MathML

You can export a worksheet to HTML and automatically convert all mathematical output into MathML. To do this, follow these steps:

  1. Open the worksheet that you want to export.

  2. Choose File Export As HTML with MathML.

  3. In the Save As dialog that appears, specify a name and location for the file, and then click OK.

  4. The HTML options dialog is displayed. Use the Save Mathematical Expressions As pop-up menu to specify the type of MathML you want to produce.

  5. Click OK.

An HTML version of the worksheet that contains embedded MathML equations is saved in the location you specified. Parts of the worksheet that cannot be saved as HTML (such as graphics) are saved as GIF images. By default, any images produced are saved in an images directory located in the same directory as the HTML document. You can choose the particular type of MathML in which to save formulas using the HTML Options dialog (Figure 11.15).


Figure 11.15: The HTML Options dialog, which shows the options available for saving formulas in a worksheet as MathML.

Conversion from Maple worksheets to HTML+MathML documents is not reversible. That is, you cannot import an HTML+MathML document produced in this way into Maple and convert it back into a worksheet for doing further calculations. This type of two-way conversion, however, is supported in Mathcad.

MathML Conversion Functions

Maple (Version 7 or later) contains a number of functions for converting Maple expressions to different types of MathML and vice versa. These functions are all contained in a package called MathML.

Each Maple package consists of a set of specialized functions that deal with a specific topic. Unlike the top-level functions (such as integrate or sin, which can be evaluated if you just specify the function name), package functions must be prefaced with the name of the package.

For example, the MathML package contains a function called Export, which converts a Maple expression into MathML. Hence, to evaluate this function, the Maple command would be:

    MathML[Export](arg); 

This is called the long form of the function name. Alternatively, you can first load the package using the with command. You can then refer to functions in the package using their short names; that is, without using the package name as a prefix. Doing this is useful when you intend to use one or more functions from a package repeatedly in the same Maple session.

The following two commands are equivalent to the single command just given:

    with(MathML); Export(arg); 

Converting Maple Syntax to MathML

The MathML package contains three functions for converting a Maple expression into a MathML:

  • MathML[Export](expr): converts a Maple expression into a MathML string. The resulting MathML is in the form of combined markup with three separate encodings enclosed in parallel in a semantics tag: presentation markup followed by content markup enclosed in an annotation-xml followed by a textual representation of the Maple syntax for the input expression enclosed in an annotation element. This allows Maple to recover the original input if it encounters the same MathML expression.

  • MathML[ExportContent](expr): converts a Maple expression into content MathML. This is faster and more efficient than using the MathML[Export] function, which must produce three separate encodings of the same expression.

  • MathML[ExportPresentation](expr): converts a Maple expression into presentation MathML. This works by first generating a full parallel encoding for the specified expression and then stripping off the content MathML and Maple annotations. Hence, it is not more efficient or faster than using MathML[Export].

Here are some examples showing how these functions work.

The following command produces combined markup, with both presentation and content markup representations of the Maple expression, enclosed in a semantics tag:

     MathML[Export](x^2+sqrt(x));    "<math mlns='http://www.w3.org/1998/Math/MathML'>    <semantics><mrow xref='id6'><mrow xref='id3'><msup>    <mi xref='id1'>x</mi><mn xref='id2'>2</mn></msup>    </mrow><mo>+</mo><mrow xref='id5'><msqrt>    <mi xref='id4'>x</mi></msqrt></mrow></mrow>    <annotation-xml encoding='MathML-Content'><apply id='id6'>    <plus/><apply id='id3'><power/><ci id='id1'>x</ci>    <cn id='id2' type='integer'>2</cn></apply><apply id='id5'>    <root/><ci id='id4'>x</ci></apply></apply></annotation-    xml><annotation encoding='Maple'>x^2+x^(1/2)</annotation>     </semantics></math>" 

Notice that the output elements contain the id and xref attributes for fine-grained cross-referencing. As explained in Section 6.3, the purposes of these attributes is to establish a correspondence between the content and presentation markup for each subexpression of the overall expression.

The following command produces content markup only:

     MathML[ExportContent](x^2+sqrt(x));    "<math xmlns='http://www.w3.org/1998/Math/MathML'>    <apply id='id6\'><plus/><apply id='id3'><power/>    <ci id='id1'>x</ci><cn id\='id2' type='integer'>2</cn>    </apply><apply id='id5'><root/><ci id='id4'>x</ci>     <dis2> </apply></apply></math>" 

The following command produces presentation markup only:

     MathML[ExportPresentation](x^2+sqrt(x));    "<math xmlns=     'http://www.w3.org/1998/Math/MathML'>    <mrow><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo>    <msqrt><mi>x</mi></msqrt></mrow></math>" 

You can use the Print function contained in the XMLTools package to print the output in a tab-indented form in the worksheet, or XMLTools[PrintToFile](filename, %) to print the tab-indented output to a file. The % symbol is the Maple notation to represent the result of the last calculation you did in the worksheet. Here is an example showing the output from XMLTools:

     XMLTools[Print](%)    <math xmlns='http://www.w3.org/1998/Math/MathML'>      <mrow>        <msup>          <mi>x</mi>          <mn>2</mn>        </msup>        <mo>+</mo>        <msqrt>          <mi>x</mi>        </msqrt>      </mrow>     </math> 

Converting MathML to Maple Syntax

The MathML package contains two functions for converting a MathML expression into a Maple expression. Both functions take as their argument a MathML expression specified as a string. The first is:

    MathML[Import](mmlstring) - 

This converts into a Maple expression parallel combined markup that contains both the presentation MathML and content MathML representation of an expression. This function will also attempt a conversion on presentation markup in cases where it is possible to do so unambiguously. If the conversion fails, the function returns an error message. Here is an example showing the effect of MathML[Import]:

    MathML[Import]("<math><msup><mi>x</mi><mn>2</mn>          </msup></math>"); 

x2

The second function is:

    MathML[ImportContent](mmlstring) - 

This converts a content MathML expression into a Maple expression. If the conversion fails, Maple produces an error message. Here is an example showing the effect of MathML[ImportContent]:

    MathML[ImportContent]("<math><apply><power/>          <ci>x</ci><cn>2</cn></apply></math>"); 

x2



 < Day Day Up > 



The MathML Handbook
The MathML Handbook (Charles River Media Internet & Web Design)
ISBN: 1584502495
EAN: 2147483647
Year: 2003
Pages: 127
Authors: Pavi Sandhu

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net