When is it necessary to define a function in "syms"?
Show older comments
What is the difference between the following two codes? They both work. When is it necessary to define a function in "syms"?
syms f(x)
f(x)=x^2
f(2)
syms x
f(x)=x^2
f(2)
Answers (1)
Walter Roberson
on 29 Jan 2019
Edited: Walter Roberson
on 29 Jan 2019
It is necessary to define a function in syms when you are creating a symbol to designate an unknown function. For example,
syms f(x)
dsolve( diff(f,x) == cos(x) )
It is not possible to create an indefinite function using symfun() or assignment to f(x), or using feval(symengine) or evalin(symengine) or str2sym(). However it is possible to use
g = symfun(str2sym('g(x)'),x)
h(x) = str2sym('h(x)')
Only syms() and symfun() and assignment to something indexed at a sym have the logic to "bless" a symbolic variable into being of the correct class.
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!