| Contents | Index |
| On this page… |
|---|
Creating, Opening, and Saving MuPAD Notebooks Calculating in a MuPAD Notebook Editing and Debugging MuPAD Code |
Extensive online help is available for MuPAD. To access the MuPAD Help Browser from the MATLAB workspace, use one of the following methods:
Enter doc(symengine) at the MATLAB Command Window.

MuPAD Help contains complete documentation of the MuPAD language. It also explains how to use MuPAD interfaces, such as notebooks and the editor.
For help on a specific MuPAD function, enter doc(symengine,'functionName') at the MATLAB command line to display MuPAD Help at the functionName function.
To create a new MuPAD notebook from the MATLAB command line, enter
nb = mupad
You can use any variable name instead of nb. This syntax opens a blank MuPAD notebook.
The variable nb is a handle to the notebook. The toolbox uses this handle only for communication between the MATLAB workspace and the MuPAD notebook. Use handles as described in Copying Variables and Expressions Between the MATLAB Workspace and MuPAD Notebooks.
You also can open an existing MuPAD notebook file named file_name from the MATLAB command line by entering
nb2 = mupad('file_name')where file_name must be a full path unless the notebook is in the current folder. This command is useful if you lose the handle to a notebook, in which case, you can save the notebook file and then reopen it with a fresh handle.
Caution You can lose data when saving a MuPAD notebook. A notebook saves its inputs and outputs, but not the state of its engine. In particular, MuPAD does not save variables copied into a notebook using setVar(nb,...). |
To open a notebook and automatically jump to a particular location, create a link target at that location inside a notebook and refer to it when opening a notebook. For information about creating link targets, see "Formatting and Exporting MuPAD Documents and Graphics" in the "Getting Started" chapter of the MuPAD documentation. To refer to a link target when opening a notebook, enter:
nb2 = mupad('file_name#linktarget_name')You also can open and save MuPAD notebook files using the usual file system commands, and by using the MATLAB or MuPAD File menu. However, to be able to use a handle to a notebook, you must open the notebook using the mupad command at the MATLAB command line.
Tip MuPAD notebook files open in an unevaluated state. In other words, the notebook is not synchronized with its engine when it opens. To synchronize a notebook with its engine, select Notebook > Evaluate All. For details, see Synchronizing a Notebook and its Engine. |
You also can use the Welcome to MuPAD dialog box to access various MuPAD interfaces. To open this dialog box, enter:
mupadwelcome

To access MuPAD Help, click one of the three options in the First Steps pane.
To open an existing file, click its name in the Open Recent File pane.
To open a new notebook, click the New Notebook button.
To open a new program file in the MuPAD Editor, click the New Editor button. For information on this interface and its associated debugger, see Editing and Debugging MuPAD Code.
To open an existing MuPAD notebook or program file, click Open File and navigate to the file.
Alternatively, you can open the MuPAD welcome dialog box from the MATLAB Start menu.

A MuPAD notebook has the following main components.

Enter commands for execution, evaluation, or plotting in input regions.
Enter comments in text regions. You can type and format text in a notebook similar to working in any word processing application.
Use the Command Bar to help you enter commands into input regions with the proper syntax.
Use the Insert menu to add a text area (called Text Paragraph) or input regions (called Calculation).
Use the Notebook menu to evaluate expressions in input regions.
The MuPAD notebook interface differs from the MATLAB interface. Things to remember when working in a MuPAD notebook are:
Commands typed in an input area are not evaluated until you press Enter.
You can edit the commands typed in any input area. For example, you can change a command, correct syntax, or try different values of parameters simply by selecting the area you want to change and typing over it. Press Enter to reevaluate the result.
Results do not automatically cascade or propagate through a notebook, as described in Cascading Calculations.
The MATLAB method of recalling a previous command by pressing an up arrow key does not have the same effect in a MuPAD notebook. Instead, you use arrow keys for navigation in MuPAD notebooks, similar to most word processors.
If you change a variable in a notebook, the change does not automatically propagate throughout the notebook. For example, consider the following set of MuPAD commands:

Now change the definition of z in the first line of the notebook from sin(x) to cos(x) and press Enter:

Only the first line was reevaluated. Therefore y and z are no longer synchronized. The notebook is in an inconsistent state.
To have the changes cascade to all parts of the notebook, select Notebook > Evaluate All.

The engine evaluates all the expressions in the notebook from top to bottom, and the notebook becomes consistent:

When you open a saved MuPAD notebook file, the notebook display is not synchronized with its engine. For example, suppose you saved the notebook pictured in the start of Cascading Calculations:

If you open that file and immediately try to work in it without synchronizing the notebook with its engine, the expressions in the notebook display are unavailable for calculations. For example, try to calculate u := (1+w)/w:

The variable w has no definition as far as the engine is concerned.
To remedy this situation, select Notebook > Evaluate All. The variable u changes to reflect the value of w:

When you work in the MATLAB Command Window, the default interface for editing MuPAD code is the MATLAB Editor. Alternatively, you can create and edit your code in any text editor or in the MuPAD Editor.
The MATLAB Editor automatically formats the code and, therefore, helps you avoid errors, or at least reduce their number. For details about the MATLAB Editor, see Editing and Debugging MATLAB Code in MATLAB Desktop Tools and Development Environment.
To open an existing MuPAD file with the extension .mu in the MATLAB Editor, double-click the file name or select File > Open and navigate to the file.

After editing the code, save the file. Note that the extension .mu allows the Editor to recognize and open MuPAD program files. Thus, if you intend to open the files in the MATLAB Editor, save them with the extension .mu. Otherwise, you can specify other extensions suitable for text files, for example, .txt or .tst.
Symbolic Math Toolbox also provides the MuPAD Editor, which is another interface for editing MuPAD code. When you work in the MuPAD notebook interface, the MuPAD Editor is the default interface for creating and editing MuPAD program files. When you work in the MATLAB Command Window, you can still choose to use the MuPAD Editor.
If you work in the MATLAB Command Window, open an existing MuPAD program file in the MuPAD Editor using the mupad function. (If you double-click the file name, the system opens that file in the MATLAB Editor.) For example, enter mupad('filename.mu') to open the filename.mu program file. To create a new program file in the MuPAD Editor, open the Welcome to MuPAD dialog box and click New Editor. For more ways to open the MuPAD Editor window, see Opening MuPAD Interfaces from MATLAB.
After opening or creating a file in the MuPAD Editor, you can type mathematical expressions, commands, and text as you would in a notebook. The MuPAD Editor automatically highlights and indents your code.

The MuPAD Editor saves files in text format. By default, it uses the extension .mu. You can specify other extensions, for example, .txt or .tst.
For more information about the MuPAD Editor, see "Using the MuPAD Editor to Write New Functions" in the MuPAD documentation.
The MuPAD Debugger helps you find run-time errors in your code. This interface lets you:
Execute your code step by step.
Set breakpoints, including conditional breakpoints.
Observe the values of the variables and expressions in each step.
To open the Debugger:
Open a new or existing MuPAD notebook. For instructions, see Creating, Opening, and Saving MuPAD Notebooks.
In the main menu of a notebook, select Notebook > Debug.
In the resulting dialog box, enter the procedure call that you want to debug.
Alternatively, use the debug function in the MuPAD notebook.

The default layout of the Debugger window displays four panes:
The main pane (top-left by default) displays the code that you debug. The Debugger only shows the code, but does not allow you to update it.
The Output pane lets you type an expression and evaluate it anytime during the debugging process.
The Watch pane shows values of the variables at each step during the debugging process.
The Call Stack pane shows the names of the procedures that you debug.
You can close any pane, except for the main pane. If you close a pane, you can restore it again by selecting View and the name of the required pane. Using the View menu, you can also open the Breakpoints pane that shows the list of breakpoints in the code.
You cannot fix bugs directly in the Debugger window. If you work in the Debugger window and want to edit the code:
Open the file with the code in the MuPAD Editor.
Close the Debugger if it is open.
Update the code in the MuPAD Editor and save it.
Open a notebook.
In the notebook, select Notebook > Read Commands from the main menu and navigate to your updated file.
Open the Debugger from the notebook.
For details about the MuPAD Debugger, see "Tracing Errors with the MuPAD Debugger" in the MuPAD documentation.
The two main types of files in MuPAD are:
Notebook files, or notebooks
Program files
A notebook file has the extension .mn and lets you store the result of the work performed in the notebook interface. A notebook file can contain text, graphics, and any MuPAD commands and their outputs. A notebook file can also contain procedures and functions.
By default, a notebook file opens in the notebook interface. Creating a new notebook or opening an existing one does not automatically start the MuPAD engine. This means that although you can see the results of computations as they were saved, MuPAD does not remember evaluating them. (The "MuPAD Workspace" is empty.) You can evaluate any or all commands after opening a notebook.
A program file is a text file that contains any code snippet that you want to store separately from other computations. Saving a code snippet as a program file can be very helpful when you want to use the code in several notebooks. Typically, a program file contains a single procedure, but it also can contain one or more procedures or functions, assignments, statements, tests, or any other valid MuPAD code.
Tip If you use a program file to store a procedure, MuPAD does not require the name of that program file to match the name of a procedure. |
The most common approach is to write a procedure and save it as a program file with the extension .mu. This extension allows the MATLAB Editor and the MuPAD Editor to recognize and open the file later. Nevertheless, a program file is just a text file. You can save a program file with any extension that you use for regular text files.
To evaluate the commands from a program file, you must execute a program file in a notebook. For details about executing program files, see Reading MuPAD Procedures.
You can display the source code of the MuPAD built-in library functions. If you work in the MuPAD notebook interface, enter expose(name), where name is the library function name. The notebook interface displays the code as plain text with the original line breaks and indentations.
You can also display the code of a MuPAD library function in the MATLAB Command Window. To do this, use the evalin or feval function to call the MuPAD expose function:
sprintf(char(feval(symengine, 'expose', 'numlib::tau')))
ans =
proc(a)
name numlib::tau;
begin
if args(0) <> 1 then
error(message("symbolic:numlib:WrongNumberOfArguments"))
else
if not testtype(a, Type::Numeric) then
return(procname(args()))
else
if domtype(a) <> DOM_INT then
error(message("symbolic:numlib:ArgumentInteger"))
end_if
end_if
end_if;
numlib::numdivisors(a)
end_procMuPAD also includes kernel functions written in C++. You cannot access the source the code of these functions.
![]() | Understanding MuPAD | Integration of MuPAD and MATLAB | ![]() |

See how symbolic computations can help you find analytical solutions to math and engineering problems.
Get free kit| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |