Symbolic substitution (subs) doesn't work with negative expressions
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Does the SUBS function have a bug when expressions have a negative sign in them? Why isn't the second output (a - c)?
clear all;
syms a b c
disp( subs(a + 2*b, 2*b, c) );
disp( subs(a - 2*b, 2*b, c) ); % The only difference is the negative sign
disp( subs(a - 2*b, -2*b, c) ); % Works if substituting -2*b instead of 2*b
Output:
a + c
a - 2*b
a + c
0 comentarios
Respuestas (2)
Walter Roberson
el 5 de Ag. de 2013
You should use MuPAD's op() and type() functions in order to explore the internal structure of each of the expressions. For example it is possible that the expression a - 2*b is stored internally as
_subtract(a, _mult(b, 2))
and that -2*b in the subs() call is being stored internally as
_negate(_mult(b, 2))
or
_mult(b, -2)
As _mult(b, -2) is not a subtree of _subtract(a, _mult(b, 2)) then the subs() would fail.
When I read through the documentation in the symbolic toolbox, I would expect that the representations would be _plus(a, _mult(b, -2)) and _mult(b, -2) in which case the subs() should succeed, but I do not have that toolbox to test with, and the alternate representations I showed are plausible ones that could potentially be triggered by the MATLAB to MuPAD interface.
0 comentarios
Ver también
Categorías
Más información sobre Special Values en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!