Bug? sym alpha takes precedence over matlab's alpha.m at the command line, but not within a matlab function.

1 visualización (últimos 30 días)
When I run the following code, there is no problem:
syms xDot(t) t alpha
dF_dxDot = @(t) -exp(-t)*alpha*xDot(t)^(alpha-1);
Euler = matlabFunction(simplify(diff(dF_dxDot(t),t)),'vars',[t,alpha]);
But when I run the same code within a function.
function nothing
syms xDot(t) t alpha
dF_dxDot = @(t) -exp(-t)*alpha*xDot(t)^(alpha-1);
Euler = matlabFunction(simplify(diff(dF_dxDot(t),t)),'vars',[t,alpha]);
it throws an error,
Error using alpha
Too many output arguments.
since
which alpha
returns
/usr/local/MATLAB/R2016a/toolbox/matlab/graph3d/alpha.m
what appears to be happening is that my sym command takes precedence over matlab's command, provided I run the code within a regular script, but the precedence is reversed when I run it within a function. Surely this has to be a bug???

Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Mayo de 2016
Editada: Walter Roberson el 10 de Sept. de 2019
This effect is documented... somewhere or other, I do not recall where. It occurs only in quite recent versions of MATLAB. It occurs because the JIT (Just In Time) compiler now gives priority to function calls to known routines, whereas before it gave priority to run-time assignments that are hidden with assignin().
syms is not a command: syms is a function. In its basic form, it is equivalent to
function syms(varargin)
for K = 1 : nargin
symname = varargin{K};
assignin('caller', symname, sym(symname));
end
end
It "poofs" variables into existence -- and MATLAB now gives priority to static analysis over dynamic analysis.
To avoid this problem, use
alpha = sym('alpha');
or any assignment to alpha before the syms call. For example,
alpha = [];
syms alpha
will do fine.

Más respuestas (0)

Categorías

Más información sobre Formula Manipulation and Simplification 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!

Translated by