Reserved Variable and Function Names

Both MATLAB® and MuPAD® have their own reserved keywords, such as function names, special values, and names of mathematical constants. Using reserved keywords as variable or function names can result in errors. If a variable name or a function name is a reserved keyword in one or both interfaces, you can get errors or incorrect results. If you work in one interface and a name is a reserved keyword in another interface, the error and warning messages are produced by the interface you work in. These messages can specify the cause of the problem incorrectly.

    Tip   The best approach is to avoid using reserved keywords as variable or function names, especially if you use both interfaces.

In MuPAD, function names are protected. Normally, the system does not let you redefine a standard function or use its name as a variable. (To be able to modify a standard MuPAD function you must first remove its protection.) Even when you work in the MATLAB Command Window, the MuPAD engine handles symbolic computations. Therefore, MuPAD function names are reserved keywords in this case. Using a MuPAD function name while performing symbolic computations in the MATLAB Command Window can lead to an error:

solve('D - 10')

The message does not indicate the real cause of the problem:

Error using solve (line 263)
Specify a variable for which you solve. 

To fix this issue, use the syms function to declare D as a symbolic variable. Then call the symbolic solver without using quotes:

syms D
solve(D - 10)

In this case, the toolbox replaces D with some other variable name before passing the expression to the MuPAD engine:

ans =

To list all MuPAD function names, enter this command in the MATLAB Command Window:

evalin(symengine, 'anames()')

If you work in a MuPAD notebook, enter:

Was this topic helpful?