Is this a bug of MATLAB?

조회 수: 2 (최근 30일)
M. Wang
M. Wang 2024년 8월 25일
댓글: Image Analyst 2024년 8월 25일
% Here is my code
[vpa(str2sym('asin(1)*2'),100);vpa(str2sym('pi'),100)]
The output is:
3.1415926535897932384626433832795
3.1415926535897932384626433832795
I think the correct answer should be longer. Is it a bug or an expected behavior?

채택된 답변

Stephen23
Stephen23 2024년 8월 25일
편집: Stephen23 2024년 8월 25일
"I think the correct answer should be longer. Is it a bug or an expected behavior?"
It is not a bug: the default number of digits is 32:
When you create a new symbolic array it will be displayed using the default number of digits:
d = digits
d = 32
a = vpa(str2sym('asin(1)*2'),100)
a = 
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
b = vpa(str2sym('pi'),100)
b = 
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
c = [a,b] % uses the default number of digits
c = 
d = digits(100) % returns the PREVIOUS default digits, set NEW default digits
d = 32
c = [a,b]
c = 
  댓글 수: 1
Image Analyst
Image Analyst 2024년 8월 25일
@M. Wang, pi has an infinite number of digits. Obviously not all of them can be displayed. How many digits did you expect to be installed, and how many do you want or need to be displayed?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by