Numerical Calculations

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, 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. For instance, you can select to only run a section of your code instead of all of it.

Try typing into the top text line and executing a simple calculator function:

This is a test

2+2
\( \displaystyle 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.

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. MuPAD inputs will appear in red and the corresponding outputs below it are 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 (\( \displaystyle \sin\frac{\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