Basics of MuPAD

Brown University, Applied Mathematics


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!

Home

< Previous

Next >