Azzera filtri
Azzera filtri

A problem with symsum() and isAlways

2 visualizzazioni (ultimi 30 giorni)
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)))

Risposta accettata

Neeraj Kulkarni
Neeraj Kulkarni il 16 Set 2020
Modificato: Neeraj Kulkarni il 16 Set 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 Commento
Walter Roberson
Walter Roberson il 16 Set 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"

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by