Is Assignment from symmatrix/symfunmatrix Consistent with Assignment from sym/symfun ?

23 次查看(过去 30 天)
I've just started using symmatrix and symfunmatrix and noticed a behavior that I don't understand and seems to be inconsistent with sym and symfun.
clear all
syms t
syms zfun(t)
zfun(t) = t;
class(zfun)
ans = 'symfun'
Consider four ways to assign from zfun to a new variable h
h = zfun; class(h), clear h % 1
ans = 'symfun'
h = zfun(t); class(h), clear h % 2
ans = 'sym'
h(t) = zfun(t); class(h), clear h % 3
ans = 'symfun'
h(t) = zfun; class(h), clear h % 4
ans = 'symfun'
Cases 1-4 work as I expect, at least based on experience (not sure what the doc states)
Now try the same thing for assigning from a symfunmatrix
clear all
syms t
zfun = symfunmatrix('zfun(t)',t,[3,1]);
zfun(t) = [t;t;t];
class(zfun)
ans = 'symfunmatrix'
h = zfun; class(h), clear h % 5
ans = 'symfunmatrix'
h = zfun(t); class(h), clear h % 6
ans = 'symmatrix'
h(t) = zfun(t); class(h), clear h % 7
ans = 'symmatrix'
try
h(t) = zfun; class(h), clear h % 8
catch ME
ME.message
end
ans = 'Undefined function 'argnames' for input arguments of type 'double'.'
I was expecting cases 5-8 be analagous with cases 1-4.
But case 7 returns a symmatrix into h, contra to a symfun as in case 3, even though the the LHS of the case 7 assignment has a functional form.
Case 8 throws an error altogether, though the caught message seems irrelevant to whatever the error actually was.
Am I missing something as to expected behavior of cases 7 and 8?
The workaround is to define h(t) before the assignment, but that seems inconsistent the symfun cases.
h = symfunmatrix('h(t)',t,[3,1]);
h(t) = zfun(t); class(h)
ans = 'symfunmatrix'
h(t) = zfun; class(h)
ans = 'symfunmatrix'
FWIW, we can see the true error for case 8 by executing outside of the try/catch construct.
clear h
h(t) = zfun;
Incorrect number or types of inputs or outputs for function argnames.

Error in symbolic.validators.mustBeCompatibleReferenceStruct (line 17)
Yvars = argnames(Y);
^^^^^^^^^^^^^^^^^^^^
Error in indexing (line 260)
S {symbolic.validators.mustBeCompatibleReferenceStruct(S, A)}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4 个评论
Paul
Paul 2025-10-16,23:17
编辑:Paul 2025-10-17,11:48
If h(t) = zfun is defined to be the same as h = symfun(zfun,t), then I don't understand why those commands result in different error messages.
Actual error messages from try/catch:
clear all;syms t;zfun = symfunmatrix('z(t)',t,[3,1]);
try,h(t) = zfun;catch ME,ME.message,end
ans = 'Undefined function 'argnames' for input arguments of type 'double'.'
clear all;syms t;zfun = symfunmatrix('z(t)',t,[3,1]);
try,h = symfun(zfun,t);catch ME,ME.message,end
ans = 'Too many input arguments.'
I wonder how "type 'double' " gets involved here. Anyway ...
What the user would typically see.
Interesting to me that the error message for the second case in 2025b has been changed from what it was in 2024a
%Error using symfun (line 139)
%First argument must be a symbolic expression.
IMO, none of the error messages in this thread are actually helpful to the user. In particular, how can two inputs to symfun be too many, when two inputs to symfun is a documented usage?
Upon reviewing the doc, I see now that for symfun
is a documented usage, but symfunmatrix doesn't have an analagous command. So I guess, but I'm not sure, that
h(t) = zfun
is not a defined operation?
Presumably it would be an enhancement request for h(t) = zfun to work for zfun being a symfunmatrix in the same way it works for zfun being symfun, i.e., h(t) is a symfunmatrix in the former and symfun in the latter.
Still don't know what's going on with case 7.
Or maybe I'm missing something unique to the symmatrix/symfunmatrix cases that preclude the desired behavior (well, at least desired by me).

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

产品


版本

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by