Reserved Variable and Function Names


MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

To convert a MuPAD notebook file to a MATLAB live script file, see convertMuPADNotebook. MATLAB live scripts support most MuPAD functionality, although there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Both MATLAB and MuPAD have their own reserved keywords, such as function names, special values, and names of mathematical constants. In MATLAB, if you supply an expression or equation as a string scalar or character vector to any symbolic function other than str2sym, and the input text contains reserved keywords as variable or function names in at least one interface, then an error can result. If you work in one interface and a name is a reserved keyword in the other, then the interface you are working in produces the error and warning messages. These messages can specify the cause of the problem incorrectly.


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. For example:

evalin(symengine,'solve(D - 10)')
Error using symengine
Invalid argument.

Error in mupadengine/evalin (line 132)
                res = mupadmex(statement,output_type{:});

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

To fix this issue, use the syms function to declare D as a symbolic variable. Then, pass the equation to the symbolic solver as a symbolic expression (that is, do not specify the equation as a string scalar or character vector).

syms D
solve(D - 10)
ans =

In this case, the software replaces D with another variable name before passing the expression to the MuPAD engine.

Alternatively, convert an equation, which is specified as a string scalar or character vector and contains an undeclared, reserved variable name, to a symbolic expression using str2sym. Then, supply the expression to solve. For example:

clear all
expsn = str2sym("D - 10");
ans =