Skip to Main Content Skip to Search
Product Documentation

MuPAD for MATLAB Users

Getting Help for MuPAD

Extensive online help is available for MuPAD. To access the MuPAD Help Browser from the MATLAB workspace, use one of the following methods:

Creating, Opening, and Saving MuPAD Notebooks

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.

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.

You also can use the Welcome to MuPAD dialog box to access various MuPAD interfaces. To open this dialog box, enter:

mupadwelcome

Alternatively, you can open the MuPAD welcome dialog box from the MATLAB Start menu.

Calculating in a MuPAD Notebook

Visual Elements of a Notebook

A MuPAD notebook has the following main components.

Working in a Notebook

The MuPAD notebook interface differs from the MATLAB interface. Things to remember when working in a MuPAD notebook are:

Cascading Calculations

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:

Synchronizing a Notebook and its Engine

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:

Editing and Debugging MuPAD Code

Using the MATLAB Editor

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.

Using the MuPAD Editor

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.

Using the MuPAD Debugger

The MuPAD Debugger helps you find run-time errors in your code. This interface lets you:

To open the Debugger:

  1. Open a new or existing MuPAD notebook. For instructions, see Creating, Opening, and Saving MuPAD Notebooks.

  2. In the main menu of a notebook, select Notebook > Debug.

  3. 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:

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:

  1. Open the file with the code in the MuPAD Editor.

      Tip   If you did not yet save this code to a program file, display the code in a new Editor window by selecting File > New Editor with Source.

  2. Close the Debugger if it is open.

  3. Update the code in the MuPAD Editor and save it.

  4. Open a notebook.

  5. In the notebook, select Notebook > Read Commands from the main menu and navigate to your updated file.

  6. Open the Debugger from the notebook.

For details about the MuPAD Debugger, see "Tracing Errors with the MuPAD Debugger" in the MuPAD documentation.

Notebook Files and Program Files

The two main types of files in MuPAD are:

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.

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.

Source Code of the MuPAD Library Functions

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_proc

MuPAD also includes kernel functions written in C++. You cannot access the source the code of these functions.

  


Free Symbolic Math Interactive Kit

See how symbolic computations can help you find analytical solutions to math and engineering problems.

Get free kit

Trials Available

Try the latest version of symbolic math products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS