Bug? sym alpha takes precedence over matlab's alpha.m at the command line, but not within a matlab function.
1 回表示 (過去 30 日間)
古いコメントを表示
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???
0 件のコメント
採用された回答
Walter Roberson
2016 年 5 月 3 日
編集済み: Walter Roberson
2019 年 9 月 10 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!