Increase Speed by Decreasing Precision

Increase the speed of MATLAB calculations
by using vpa with a lower precision. Set the
lower precision by using digits.

First, find the time taken to perform an operation on a large
input.

input = 1:0.01:500;
tic
zeta(input);
toc

Elapsed time is 48.968983 seconds.

Now, repeat the operation with a lower precision by using vpa.
Lower the precision to 10 digits by using digits.
Then, use vpa to reduce the precision of input and
perform the same operation. The time taken decreases significantly.

Guard Digits

The number of digits that you specify using the vpa function
or the digits function is the guaranteed number
of digits. Internally, the toolbox can use a few more digits than
you specify. These additional digits are called guard digits.
For example, set the number of digits to 4, and then display the floating-point
approximation of 1/3 using four digits:

old = digits(4);
a = vpa(1/3)

a =
0.3333

Now, display a using 20 digits. The result
shows that the toolbox internally used more than four digits when
computing a. The last digits in the following result
are incorrect because of the round-off error:

digits(20)
vpa(a)
digits(old)

ans =
0.33333333333303016843

Hidden Round-Off Errors

Hidden round-off errors can cause unexpected results. For example,
compute the number 1/10 with the default 32-digit accuracy and with
10-digit accuracy:

a = vpa(1/10)
old = digits(10);
b = vpa(1/10)
digits(old)

a =
0.1
b =
0.1

Now, compute the difference a - b. The result
is not 0:

a - b

ans =
0.000000000000000000086736173798840354720600815844403

The difference a - b is not equal to zero
because the toolbox internally boosts the 10-digit number b
= 0.1 to 32-digit accuracy. This process implies round-off
errors. The toolbox actually computes the difference a -
b as follows:

Techniques Used to Convert Floating-Point Numbers to Symbolic Objects

Suppose you convert a double number to a symbolic object, and
then perform VPA operations on that object. The results can depend
on the conversion technique that you used to convert a floating-point
number to a symbolic object. The sym function lets
you choose the conversion technique by specifying the optional second
argument, which can be 'r', 'f', 'd',
or 'e'. The default is 'r'.
For example, convert the constant π = 3.141592653589793... to
a symbolic object:

Input Arguments

d — New accuracy settingnumber | symbolic number

New accuracy setting, specified as a number or symbolic number.
The setting specifies the number of significant decimal digits to
be used for variable-precision calculations. If the value d is
not an integer, digits rounds it to the nearest
integer.