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

5 次查看(过去 30 天)
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)

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2024-4-18
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 个评论
Walter Roberson
Walter Roberson 2021-12-13
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 2024-4-18
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{:});

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematical Functions 的更多信息

产品


版本

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by