Trouble substituting a value into a symbolic expression for use with fplot

2 ビュー (過去 30 日間)
Bob
Bob 2012 年 3 月 20 日
編集済み: work wolf 2017 年 12 月 11 日
I'm having difficulty understanding what I'm doing wrong here:
syms x a
f=exp(x-a);
g=subs(f,'a',sym(0));
fplot(g,[-5 5])
I get the error:
Error using fcnchk (line 103)
If FUN is a MATLAB object, it must have an feval method.Error in fplot (line 61)
fun = fcnchk(fun);
If I explicitly define g as being a symbolic function:
fplot(@(x)g,[-5 5])
Undefined function 'isfinite' for input arguments of type 'sym'.
Error in fplot (line 113)
J = find(isfinite(y));
I clearly am not understanding the way the symbolic toolbox works and would appreciate a pointer.

採用された回答

Alexander
Alexander 2012 年 3 月 20 日
The command fplot only takes function handles, not symbolic objects. The easiest way to plot symbolic objects is using ezplot:
ezplot(g,[-5 5])
If you want to use fplot, you can use the command matlabFunction to convert the symbolic object into a MATLAB anonymous function:
fplot(matlabFunction(g),[-5 5])
  4 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 11 日
fplot() does accept symbolic objects in modern versions, but did not when the question was originally asked.
work wolf
work wolf 2017 年 12 月 11 日
編集済み: work wolf 2017 年 12 月 11 日
Dear, Walter Roberson. Thanks, I had problem about using symfun with fplot(). Thus, I used
matlabFunction(f)
instead of
symfun(formula,variables)
Please, see my Question here

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by