Keystrokes and Syntax

Double click your MATLAB Icon to open the MATLAB GUI. Then you can start MuPAD by typing

>> mupad

You will see the screen that should appear

This is your MuPad shell. You can type commands into this window, and it will solve problems for you. You can type commands into this window, and it will compile them automatically and give you an answer. The shell is great, but it works off of Random Access Memory and will not save your variables or work once you close the program. This is why most people write a script, or a savable document that can perform your calculations through the shell. To open an existing MuPAD file with the extension .mu in the MATLAB Editor, double-click the file name or select 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.

For our purposes, we want to launch the MuPad Notebook. This is simply a program inside of MATLAB that works better for the calculations we will be making. Most of the buttons should be self-explanatory.

NOTE: MuPAD distinguishes between uppercase and lowercase. Most common errors are found because a variable word was either spelled wrong or had some form of wrong capitalization.  

In a MuPAD™ notebook, you can convert characters in the text region to Greek letters one at a time:

a) Select the character you want to convert or place the cursor to the right of the character.

b) Select Edit>Toggle Greek.

For example, display the Greek letter δ by typing d and then placing your cursor to the right of d and selecting Edit>Toggle Greek.

Symbol::new(symname) or simply Symbol(symname) creates the typesetting symbol corresponding to symname.

The typesetting symbols can be accessed in two different ways: Most symbols can be input by typing Symbol::symname, where symname is taken from the lists in the introduction. For some symbol names (such as not or I), this is not possible in the MuPAD® language. What is possible in any case is to invoke Symbol as a function, taking a string representation as its argument, as in Symbol("not").

Any line with an open bracket " [ " is a calculation line. Work in calculation lines will appear in red text and their answers will appear in blue text. All other lines are considered comments and plain text. These will appear in black text, and will not be executed as functions. A new calculation line can be made by pressing the red pi button located in the middle of the format toolbar, or by clicking on insert then calculation in the standard toolbar. Similarly, a new line of text can be made with the blue paragraph button to the right of the red pi button.

Pressing [Enter] after a line of code will execute that code (in a calculation line). You can change code at any time, and re-calculate it by going to the line of code and pressing [Enter] again once you’ve made your needed changes. If you have several lines to run at once, however, the first few choices under the drop-down menu "Notebook" will give you options for how to re-run your code after making changes. For instance, you can select to only run a section of your code instead of all of it to reduce computation time.

Follow along and execute a simple calculator function:

This is an arithmetic test:

[ 2+2

4

[

Notice that a new calculation line will automatically appear after you execute your line of code. Remember that you can always create a new text line after a calculation answer by clicking after the answer on the same line and pressing the blue paragraph button.

Any line with an open bracket “ [ ” is a calculation line. Work in calculation lines will appear in red text and their answers will appear in blue text. All other lines are considered comments and plain text, so they will appear in plain black text, and will not be executed as functions. A new calculation line can be made by pressing the red pi button, and a new line of text with the blue paragraph button.

Pressing [Enter] after a line of code will execute that code (in a calculation line). You can change code at any time, and re-calculate it by going to it and pressing [Enter] again. Or if you have several lines to run at once, the first few choices under the drop-down menu “Notebook” will give you options for how to re-run your code after making changes.

When you are creating a large notebook for all your homework problems, it is a good rule of thumb to have many comments telling the grader what question you are on and what calculation you just performed. Sometimes it is best to suppress the answer after a calculation (aka – run the calculation but not have it display the answer). This may sound ludicrous, but you will probably find yourself wanting to suppress answers to save space and time in the future. A colon “ : ” after an expression will suppress its output, but still perform the calculation.

Example:

[ 2+2:

[

From this point onward, I will drop the brackets before a calculation line to make the command text easier to copy and paste into your own MuPad. Calculations will appear in red and the answers below it in blue.

In addition to exact symbolic computations, most computer algebra packages can approximate solutions numerically as well. The user can set the precision to the desired number of digits. In MuPAD®, the global variable DIGITS handles this. For example, if you enter the simple command DIGITS:= 100, then MuPAD performs all floating-point calculations with a precision of 100 decimal digits. Of course, such computations need more computing time and more storage than the use of hardware floating-point arithmetic. Here are some examples.

sin{Pi/3);
\( \displaystyle \frac{\sqrt{3}}{3} \)

Notice also that, unlike MATLAB, MuPAD returns the exact answer for sin(PI/3) because by default, MUPAD is not working with floating point numbers. It returns the exact answer to any calculation.

If you want to convert the answer into floating point representation, you need first to define how many decimal places you want to see in your output. This can be accomplished by typing:

DIGITS:=16

if you want to have 16 decimal places. For instance, if you want to see floating-point approximation of the previous output (sin(PI/3)), just type:

float(%)
or
sin{Pi/3*1.0);

The output will be the same

0.86602540378443864

MuPAD knows many special functions. For example,

gamma(0.34)
2.624163256498484

besselJ(0.23,1)
0.7562982188935567

 

The imaginary unit along the vertical axis is represented in MuPAD by the symbol I in the input and an upright i in the typeset output.

You can input complex numbers in the usual mathematical notation \(x + y i\) . Note that in engineering and computer science, the unit vector in the vertical direction is denoted by j but not i. Both the real part \( x \) and the imaginary part \( y \) may be integers, rational numbers, or floating-point numbers:
(1 + 2*I)*(4 + I), (1/2 + I)*(0.1 + I/2)^3
2 + 9 i, 0.073 − 0.129 i
If you use symbolic expressions such as, e.g., sqrt(2), MuPAD may not return the result of a calculation in Cartesian coordinates:
1/(sqrt(2) + I)

\( \displaystyle \frac{1}{\sqrt{2} +i} \)

The function rectform (short for: rectangular form) ensures that the result is split into its real and imaginary parts:
rectform(1/(sqrt(2) + I))
\[
\frac{\sqrt{2}}{3} - \frac{i}{3}
\]

The functions Re and Im return the real part \(x \) and the imaginary part \( y \) , respectively, of a complex number \(x + y i\) . The functions conjugate, abs, and arg compute the complex conjugate \(x - y i\) , the absolute value \( |x + y i | = \sqrt{x^2 + y^2}\) ,
and the polar angle, respectively:
Re(1/(sqrt(2) + I)), Im(1/(sqrt(2) + I)),
conjugate(1/(sqrt(2) + I)),
abs(1/(sqrt(2) + I)), arg(1/(sqrt(2) + I)),
rectform(conjugate(1/(sqrt(2) + I)))

\[
\frac{\sqrt{2}}{3} , \quad -\frac{1}{3} , \quad \frac{1}{\sqrt{2} -i}
, \quad \frac{\sqrt{3}}{3} , \quad -\arctan \left( \frac{\sqrt{2}}{2}
\right) , \quad \frac{\sqrt{2}}{3} + \frac{i}{3}
\]

MuPAD distinguishes between uppercase and lowercase. The command
reset()
will clear all global variables so that you can start with a fresh set of letters. Because MuPad reads code from top to bottom, the reset command can be used in-between problems as a good way to clear the variable cache.

Note that unlike the MATLAB command windows, MUPAD lets you go back and change any line, and will then let you execute the file again with changed code. The NOtebook menu gives lots of options for re-doing calculations after a correction.