필터 지우기
필터 지우기

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 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