When is it necessary to define a function in "syms"?
Mostrar comentarios más antiguos
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)
Respuestas (1)
Walter Roberson
el 29 de En. de 2019
Editada: Walter Roberson
el 29 de En. de 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.
Categorías
Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!