Is Assignment from symmatrix/symfunmatrix Consistent with Assignment from sym/symfun ?
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)
Consider four ways to assign from zfun to a new variable h
h = zfun; class(h), clear h % 1
h = zfun(t); class(h), clear h % 2
h(t) = zfun(t); class(h), clear h % 3
h(t) = zfun; class(h), clear h % 4
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)
h = zfun; class(h), clear h % 5
h = zfun(t); class(h), clear h % 6
h(t) = zfun(t); class(h), clear h % 7
try
h(t) = zfun; class(h), clear h % 8
catch ME
ME.message
end
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)
h(t) = zfun; class(h)
FWIW, we can see the true error for case 8 by executing outside of the try/catch construct.
clear h
h(t) = zfun;
4 commentaires
Walter Roberson
le 16 Oct 2025 à 16:04
h(t) = zfun is defined to be the same as
h = symfun(zfun, t)
but symfun() cannot be applied to a symmatrix
Réponses (0)
Voir également
Catégories
En savoir plus sur Number Theory dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!