フィルターのクリア

A problem with symsum() and isAlways

2 ビュー (過去 30 日間)
Yang Li
Yang Li 2020 年 9 月 15 日
コメント済み: Walter Roberson 2020 年 9 月 16 日
I have defined fl=symsum(1/factorial(n),n,0,inf) and it turned out to be exp(1). But when I write "isAlways(fl==exp(1))" or "isAlways(fl==sym(exp(1))",the result is logical 0. It's cofusing.
fl=symsum(1/factorial(n),n,0,inf)
isAlways(fl==exp(1))
isAlways(fl==sym(exp(1)))

採用された回答

Neeraj Kulkarni
Neeraj Kulkarni 2020 年 9 月 16 日
編集済み: Neeraj Kulkarni 2020 年 9 月 16 日
Hi Yang Li,
sym() is to be used on subexpressions instead of entire expression for better accuracy.
For example:
>> x = sym(exp(1))
x =
3060513257434037/1125899906842624
>> x = exp(sym(1))
x =
exp(1)
The second way of creating symbolic number will give logical 1 for your isAlways() evaluation.
Please refer the following document to create symbolic numbers :
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 16 日
Right. The code that looks at floating point numbers and tries to figure out which symbolic number they represent does not try to figure out if the inputs might happen to be exp() of an "interesting" number. Using exp(sym(1)) is the correct way to proceed here.
Remember that the == operation looks for exact comparisons, never just for "equal to within roundoff errors"

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by