Clear Filters
Clear Filters

Why does the SUBS command in Symbolic Math Toolbox 5.1 (R2008b) return an error when used to substitute variable 'D'?

5 views (last 30 days)
When I execute the following:
subs('A+D','D',3)
I receive the error,
ERROR: ??? Error using ==> mupadfeval at 28
Error: Illegal operand [subs];
during evaluation of 'mlsubs'
Error in ==> sym.subs at 219
G = sym(mupadfeval('mlsubs', charcmd(G), [x '=' charcmd(y)]));
Error in ==> sym.subs at 237
G = subs(F,Y,X,0);
Error in ==> subs at 60
r = subs(sym(f),varargin{:});
This only seems to occur when the second argument of the SUBS function is the string representation of variable 'D'. This command worked perfectly in the previous version of the Symbolic Math Toolbox (R2008a)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Apr 2024
Edited: MathWorks Support Team on 18 Apr 2024
The symbol 'D' is a reserved keyword in the MuPAD engine and is used to specify the differentiation operator. This and other such keywords cannot be used in string representations of expressions in the Symbolic Math Toolbox 5.1 (R2008b). More information about this can be found at the following link: 
You can work around this by using a symbolic variable instead. For example,
syms A D
subs(A + D, D, 3)
  2 Comments
Walter Roberson
Walter Roberson on 13 Dec 2021
Related note:
Before R2020a,
syms pi
syms catalan
eulergamma
all produced symbolic references to symbolic constants -- for example
syms pi
used to indicate that the symbolic name pi should be associated with the symbolic constant π
As of R2020a, these names create plain symbolic variables that have no special meaning. Use
pi = sym(pi);
to have the variable named pi associated with the symbolic constant π -- sym() recognizes the floating point constant returned by the function pi() and converts it into a reference to the irrational constant π
Walter Roberson
Walter Roberson on 18 Apr 2024
The error cannot occur these days, as it is no longer possible to use literal expressions in subs()
subs('A+D','D',3)
Error using sym>convertChar (line 1827)
Character vectors and strings in the first argument can only specify a variable or number. To evaluate character vectors and strings representing symbolic expressions, use 'str2sym'.

Error in sym>tomupad (line 1496)
S = convertChar(x);

Error in sym (line 268)
S.s = tomupad(x);

Error in subs (line 70)
r_unique_name = subs(sym(f_unique_name),varargin{:});

Sign in to comment.

More Answers (0)

Products


Release

R2008b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!