Filter löschen
Filter löschen

A problem with symsum() and isAlways

2 Ansichten (letzte 30 Tage)
Yang Li
Yang Li am 15 Sep. 2020
Kommentiert: Walter Roberson am 16 Sep. 2020
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)))

Akzeptierte Antwort

Neeraj Kulkarni
Neeraj Kulkarni am 16 Sep. 2020
Bearbeitet: Neeraj Kulkarni am 16 Sep. 2020
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 Kommentar
Walter Roberson
Walter Roberson am 16 Sep. 2020
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"

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by