Does Symbolic Math Toolbox Formally Support Function Composition?

30 views (last 30 days)
The doc page Create Symbolic Functions states "The Symbolic Math Toolbox™ currently does not support composite symbolic functions, or symbolic functions that are functions of another symbolic functions."
But we can do
syms f(x) h(x)
y(x) = f(h(x))
y(x) = 
Is y not a composite, symbolic function?
The chain rule works as well
dy(x) = diff(y(x),x)
dy(x) = 
Is the doc wrong or am I misunderstanding the quoted statement?

Accepted Answer

Walter Roberson
Walter Roberson on 19 Nov 2025 at 3:06
This is not legal:
syms f(x) g(x)
h(f, g) = f + g
Error using indexing (line 235)
Indexing values must be positive integers, logicals, or symbolic variables. For 'symfun' data type, indexing means evaluating the function for the given value. See also 'subs'.

Error in sym/privsubsasgn (line 1183)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in indexing (line 1030)
C = privsubsasgn(L,R,inds{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3 Comments
Walter Roberson
Walter Roberson on 19 Nov 2025 at 3:10
In other words, symbolic function definitions cannot accept functions as parameters; they can only accept symbolic variables that you pass in symbolic functions in place of.
syms f(x) g(x) F G
h(F,G) = F + G
h(F, G) = 
h(f, g)
ans = 
Paul
Paul on 19 Nov 2025 at 3:42
Fair enough. But that quoted statement from the doc page should be updated along the lines of defining composite functions via symfun (or its shortcut notation) is what's not supported, as opposed to not supporting composite functions at all, which seems to be clearly not the case.

Sign in to comment.

More Answers (0)

Products


Release

R2025b

Community Treasure Hunt

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

Start Hunting!