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)

답변 (1개)

Walter Roberson
Walter Roberson 2019년 1월 29일
편집: Walter Roberson 2019년 1월 29일
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.

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

질문:

2019년 1월 29일

편집:

2019년 1월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by