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 日

0 投票

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 ExchangeSymbolic 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