Introduction

MuPAD is a registered trademark of SciFace Software GmbH & Co. KG. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Prior to the R2016a release of MATLAB® (March 2016), the MuPAD Notebook was the primary interface for performing and documenting symbolic math calculations. Starting in R2016a, the recommended approach is to use the MATLAB Live Editor.

In contrast to numerical computations, there are symbolic computations in computer algebra as computations with symbols representing mathematical objects. Here, an object may be a number, but also a polynomial, an equation, an expression or a formula, a function, a group, a ring, or any other mathematical object. Symbolic computations with numbers are carried out exactly.

Most of the current computer algebra systems can be used interactively. The user enters some formulae and commands, and the system evaluates them. Then it returns an answer, which can be manipulated further if necessary.

Moreover, modern computer algebra systems provide a powerful programming language (since the MuPAD is a version of Maple, its programming language is structured similarly to Pascal, with extensions such as language constructs for object oriented programming) and tools for visualization and animation of mathematical data. Also, many systems can produce layouted documents (known as notebooks or worksheets). The MuPAD system has such a notebook concept, but we will only sketch it briefly in this tutorial. Please check the user interface documentation instead for more details. The goal of this tutorial is to give an introduction to the mathematical power of the MuPAD language.

MATLAB is computer programming language used for numerical calculation and systems modeling. Its popularity has been growing over the past few years and has become one of the standards for use in many engineering and applied mathematical practices. MuPAD is a simple sub-language of MATLAB based on Maple's coding style. MuPAD is by far the quickest method of symbolic calculation in MATLAB, and remains mostly as powerful as Maple™. MuPADs can handle complex integration and differentiation, systems of equations, linear algebra functions, plotting, and more in mere seconds. For previous users of Maple, most of the syntax will be very similar. The goal of this tutorial is to touch on the MuPAD Notebook and show how it can be used as a quicker method of calculations, especially for homework applications.

Learn Differential Equations!

By going through this tutorial in its entirety, you will learn the equivalent material from Brown Courses APMA 0330 - equivalent to a standard sequence of Differential Equations 1 and 2 at the Undergraduate level. Topics in differential equations will be presented with the assumption of a working knowledge of Calculus I and II (up through Differential Calculus) - what is needed from Calculus III (Multivariable) and Linear Algebra will be covered in the tutorial. If you are an avid learner, you may be able to jump right in with a working knowledge of highschool calculus.

Basics

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, 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.

Try typing into the top text line and executing 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.

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.

Defining Variables and Equations

You may recall that we claimed that symbolic notation in MuPAD is quite easy. As soon as you type a letter (excluding some restricted letters*) MuPAD will declare it automatically as a variable for you.
*a few exceptions, such as the lowercase letter "i" represents a given value as defined in the MuPAD syntax. More on this can be found in the MATLAB Documentation Center on the Web and searching for "MuPAD".

For example:

x + 2
x + 2

Most of the time you will want to define (essentially name) your expressions containing variables. This will aid in further manipulation of your equations and make calculations easier.

The syntax " := " will represent "is defined as" in MuPAD. Accordingly, the syntax "=" corresponds to the logic expression "is equal in value to". The subtle difference is important. A definition assigns a particular value or expression to a variable, while a logical assignment creates a numerical relation between two variables. One is a definition, the other is a relation.

For example:
a := 2+x
2 + x
defines a variable "a" to the equation "2 + x"
y = 2 + x
y = 2 + x
tries to compare "y" to "2 + x"

In general, your response is exactly what you have typed in, something is probably wrong. Remember that you can define variables using strings of letters and numbers such as "equation1" or greek letters such as ' &Omega ' as variables as well. These types definitions are good for defining equations or setting letters to values to save you the hassle of typing too many numbers.

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.

Now that we have defined our variable "a", MuPAD will take any other "a" as a map to the global variable value of "a". The word "global" here means that once you define "a" as an expression, any time you type "a", even after thousands of lines of code or in nested loops, MuPAD will refer to your original definition. This makes long calculations much easier, but can also run you into trouble when you start using the same letters in different problems. 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.

Using our definition of "a" we can perform any operation on it:
2*a
4+2*x
a
2 + x
thus yielding an answer without changing the initial definition of "a" itself

To change the initial value of "a", we can redefine it in any way using ":=", including a recursive definition
a := a + 10
x + 12
Here we redefined our variable "a" to be 10 more than our original variable "a"

To kickstart us into the next section, we will use the "=" sign properly. Let's invoke the solve function
solve(a=0, x)
x = -12
solve equation "a" is equal to 0 for the variable x

Here we used the "=" sign in the proper manner by setting an expression equal to another expression. Don't worry too much about the "solve" function yet, we are about to jump into it!

Basic Commands

These are some basic commands that you can type into MuPAD and they will perform specific functions and calculations for you. It is necessary to know the difference between a command and a parameter. A command is a function that we will apply with parenthesis such as "solve(. . . )" and a parameter is a part of a command within the parenthesis that tells MuPAD to do a certain task or follow a certain rule when executing the command. A parameter can be the variable with which to integrate, or an exception to follow or ignore. Parameters will always be separated by commas. When it is necessary to have multiple elements in one parameter, brackets can be used to group these objects to the same parameter.

diff(function, x)
differentiates "function" with respect to the parameter - a variable input "x"
int(function, x) or int(function, x, (0,2*pi))
Integrates "function" with respect to a variable "x", or definite integral from 0 to 2*pi
solve(equation 1 = equation 2, [x,y,z])
solves a system of equations such that "equation1" = "equation2", for the variables x, y, and z
numeric::solve(equation 1 = equation 2, [x,y,z])
solves a system of equations such that "equation1" = "equation2", for the variables x, y, and z numerically
plot(equation, x = 0..10, GridVisible=TRUE)
plots "equation" for x between 0 and 10, parameter "GridVisible" turns on a plotting grid
%
recalls the previous result
subs(equation,[x=2,y(t) = t^2])
in "equation", substitutes the value 2 for "x" and "t2" for y(t)


Summation, Substitution, and Systems of Equations

In most practical cases, numerical approximation to sums (particularly infinite sums) are the most useful tool. For more abstract summation techniques, please check out the MATLAB MuPAD documentation on the web.

The general format for summation will be sum(function, n = lowerbound..upperbound)

This is very similar to the other functions we have been using - hopefully you are starting to get a hang of how most of the syntax works. Sometimes MuPAD can calculate an answer from the simple "sum" function, but usually you will have to use "numeric::sum" to get an answer. Here is an example:

numeric::sum((-1)^n/n^2,n=1..infinity)

Thus, you can effectively try to start forgetting your summation rules for what converges and what doesn't and what has a sum and what doesn't. A sum that doesn’t converge will produce the following answer:
sum(1/n,n=1..infinity)

Substitution is a very powerful tool. Because you can solve many types of equations with letters and symbols in MuPad, when you reach the final answer, sometimes it is nice to substitute in numeric values to get a numerical answer. If you wait until the final step to substitute in these values, it becomes much easier to keep subbing in new values to produce different results.

Take for instance a simple quadratic equation to solve:
quadratic := a*x^2+b*x+c

quadsolved := solve(quadratic,x)
Notice all the special cases - it gives conditions for complex cases, special cases, and insolvable cases.

The general formula for the subs function: subs(function, variable = #)

Example using our solved quadratic function:
subs(%,[a=2,b=4,c=0])
Notice that subs only has 2 parameter spaces - one for the equation and one for the variable. Because the separate variables "a, b, c" are grouped together in brackets, it counts as one parameter.

To get rid of all these conditional statements, notice that we can't try to add another parameter to the subs function. This is what will happen:
subs(quadsolved,[a=2,b=4,c=0],IgnoreSpecialCases)
Error: The argument is invalid. [subs]
To fix this, we should add, "Ignore SpecialCases" as a parameter in the solve function like we have before:
quadsolved := solve(quadratic,x,IgnoreSpecialCases)

subs(%,[a=2,b=4,c=0])

To index an answer containing multiple values, you will place a bracket containing a positive integer directly next to the value you want to index. For example, using our previous solved values from the quadratic equation, we will index to different answers:
quadsolved[1]
yields the first result from the available answers from “qualsolved”

You already know how to define equations. Now we will be using the same "solve" function to solve this linear system of equations:
r1 := a+3*b-4*c - 5:
r2 := b + a - 19:
r3 := c - b + a - 12:
solve([r1=0,r2=0,r3=0],[a,b,c])

Notice that we don't set each equation equal to a value in the definition; rather we want to apply this condition at the end in a grouped parameter condition. Also notice that we suppressed the output of these statements, thus saving much more space so that we can work faster. You can work with as many equations and variables as you want - and if it doesn't have an answer, MuPAD will try, and then tell you!

Brown Uniiversity, Applied Mathematics

Universities usually offer two courses on differential equations: one is just an introductory course (which requires basic knowledge of calculus), and another one presents further exposition of differential equations, including an introduction to partial differential equations. These courses form a main mathematical background for all students majoring in engineering, physics, geology, economics, biology, and other areas. In our days, information technologies play more and more significant role in modeling, therefore we observe a trend in an intensive use of available softwere packages. This tutorial is a part of introductory web sites that inform students, who are taking differential equations courses, with some applications of software packages that can be used. The tutorial accompanies the textbook Applied Differential Equations. The Primary Course by Vladimir Dobrushkin, CRC Press, 2015; http://www.crcpress.com/product/isbn/9781439851043

Therefore, the goal of this document is not to explain the material in the text; rather, it is to give you the tools to solve problems and to present the capabilities of available software packages as they are needed by someone studying the text. There are usually several different commands (or sets of commands) that will accomplish the same task. As a result, this tutorial will sometimes introduce several different ways to do the same thing. It is always good to be aware of these alternate pathways, but you are welcome to pick whatever notation you like the best. This tutorial can be used to introduce students who are taking the first course in differential equations (at Brown University, it is APMA 0330, Methods of Applied Mathematics - I) to a symbolic mathematical computation program MuPAD that is part of Matlab based on Maple. MuPAD is a great computer algebra system to use, especially if you are in applied areas where it is necessary to solve differential equations. MuPAD provides friendly tools to solve and plot solutions to differential equations. This computer algebra system has tremendous plotting capabilities.