symbolic toolbox problem ?

조회 수: 2 (최근 30일)
Mohammad Ehsani
Mohammad Ehsani 2020년 8월 10일
편집: John D'Errico 2020년 8월 10일
I am not sure why my symbolic toolbox truncate the numbers up to 4 digits?
vpa(pi,16);
ans =
3.1416
rounds the pi up to 4 digits
  댓글 수: 1
Star Strider
Star Strider 2020년 8월 10일
It works correctly for me:
vpa(pi,16)
produces:
ans =
3.141592653589793
That also overrides a previous digits setting:
digits(4)
so that is not the problem, either.
.

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

답변 (2개)

hosein Javan
hosein Javan 2020년 8월 10일
by default matlab vpa uses 32 digits.
old = digits(4)
vpa(pi)
old =
32
ans =
3.142
old = digits(9)
vpa(pi)
old =
4
ans =
3.14159265
if the problem persists close and reopen matlab and it would load its defauld precision of 32 digits.

John D'Errico
John D'Errico 2020년 8월 10일
편집: John D'Errico 2020년 8월 10일
A strong possibility is you have overwritten/overloaded the stored value of pi.
>> clear pi
>> pi
ans =
3.14159265358979
So, by default, pi is 3.1459265358979 in MATLAB. That is the double precision value stored in the variable pi.
Now, what happens with the symbolic toolbox?
>> digits 40
digits 40
>> vpa(pi)
ans =
3.141592653589793238462643383279502884197
sym(pi)
ans =
pi
So the symbolic toolbox knows what pi is. I have even checked, and it indeed knows those are the first 40 digits of pi. I don't know how far it goes.
hpf('pi',40)
ans =
3.141592653589793238462643383279502884197
My own toolbox, HPF, also knows the first half milloin digits of pi or so. I agrees with those 40 digits.
HOWEVER, what if you decide to overwrite pi with a variable of your own? DON'T DO THIS!!!!!!!!!!!!!
pi = 3.1416
pi =
3.1416
>> vpa(pi)
ans =
3.1416
So now, I have overwritten pi. MATLAB no longer understands that pi is that long string of digits. It thinks it to be 3.1416. BAD NEWS.
Fix that by clearing pi, and NOT overloading pi in the future.
clear pi
Again, please don't overload pi, at least not unless you happen to work for the board of education in some school districts that I will choose to leave nameless.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by