Reputation: 69
Matlab sets inputs to double precision by default, so if I input a=1/3
then the variable will be converted with double precision
>> a=1/3
a =0.3333
>> whos('a')
a 1x1 8 double
However, when I input vpa(a,100)
afterwards, I get:
ans=0.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
My question is that
since a
is at double precision and has only 8 Bytes to store its data, why can it have a precision of 100 digits when it comes to vpa(a,100)
? In a word, how does Matlab enhance the precision of a
from 'double' to 100 digits?
Upvotes: 2
Views: 114
Reputation: 1205
This is explained in the doc
page of vpa
, here is the link.
vpa Restores Precision of Common Double-Precision Inputs
Unlike exact symbolic values, double-precision values inherently contain round-off errors. When you call vpa on a double-precision input, vpa cannot restore the lost precision, even though it returns more digits than the double-precision value. However, vpa can recognize and restore the precision of expressions of the form p/q, pπ/q, (p/q)1/2, 2q, and 10q, where p and q are modest-sized integers.
First, demonstrate that vpa cannot restore precision for a double-precision input. Call vpa on a double-precision result and the same symbolic result.
So the answer is, that Matlab is smart enough to recover your expression, as it is of the form p/q
.
Upvotes: 2