Symbolic Math Toolbox 5.3
Variable Precision Arithmetic
Demonstrate variable precision arithmetic with the Symbolic Math Toolbox™ product.
Compute 19/81 to 70 digits. Notice the repeated pattern of digits. "vpa" stands for variable precision arithmetic.
vpa 19/81 70
ans = 0.2345679012345679012345679012345679012345679012345679012345679012345679
Compute pi to 780 digits. Notice the string of 9's near the end.
vpa pi 780
ans = 3.14159265358979323846264338327950288419716939937510582097494459230781640628 6208998628034825342117067982148086513282306647093844609550582231725359408128 4811174502841027019385211055596446229489549303819644288109756659334461284756 4823378678316527120190914564856692346034861045432664821339360726024914127372 4587006606315588174881520920962829254091715364367892590360011330530548820466 5213841469519415116094330572703657595919530921861173819326117931051185480744 6237996274956735188575272489122793818301194912983367336244065664308602139494 6395224737190702179860943702770539217176293176752384674818467669405132000568 1271452635608277857713427577896091736371787214684409012249534301465495853710 5079227968925892354201995611212902196086403441815981362977477130996051870721 134999999837297804995
Compute exp(sqrt(163)*pi) to 30 digits.
vpa exp(sqrt(163)*pi) 30
ans = 262537412640768743.999999999999
The value might be an integer.
Compute the same value to 40 digits.
vpa exp(sqrt(163)*pi) 40
ans = 262537412640768743.9999999999992500725972
So, the value is close to, but not exactly equal to, an integer.
Compute 70 factorial with 200 digit arithmetic.
f = vpa('70!',200)
f = 1.19785716699698917960727837216890987364589381425464258575553628646280095827 8984531968*10^100
How many digits in 70!?
parts=sscanf(char(f),'%f*10^%d');
parts(2)+1
ans = 101
Compute the eigenvalues of the fifth order magic square to 50 digits.
digits(50) A = sym(magic(5)) e = eig(vpa(A))
A =
[ 17, 24, 1, 8, 15]
[ 23, 5, 7, 14, 16]
[ 4, 6, 13, 20, 22]
[ 10, 12, 19, 21, 3]
[ 11, 18, 25, 2, 9]
e =
65.0
21.27676547147379553062642669797423083613217355600061
13.12628093070921880252564308594914382322273438650663
-13.126280930709218802525643085949143823222734386507
-21.276765471473795530626426697974230836132173556001
Store