When is it necessary to define a function in "syms"?

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)

Réponses (1)

Walter Roberson
Walter Roberson le 29 Jan 2019
Modifié(e) : Walter Roberson le 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.

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by