A problem with symsum() and isAlways

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by