Main Content


Convert symbolic values to MATLAB double precision



double(s) converts the symbolic value s to double precision. Converting symbolic values to double precision is useful when a MATLAB® function does not accept symbolic values. For differences between symbolic and double-precision numbers, see Choose Numeric or Symbolic Arithmetic.


Convert Symbolic Number to Double Precision

Convert symbolic numbers to double precision by using double. Symbolic numbers are exact while double-precision numbers have round-off errors.

Convert pi and 1/3 from symbolic form to double precision.

symN = sym([pi 1/3])
symN =
[ pi, 1/3]
doubleN = double(symN)
doubleN =
    3.1416    0.3333

For information on round-off errors, see Recognize and Avoid Round-Off Errors.

Convert Variable Precision to Double Precision

Variable-precision numbers created by vpa are symbolic values. When a MATLAB function does not accept symbolic values, convert variable precision to double precision by using double.

Convert pi and 1/3 from variable-precision form to double precision.

vpaN = vpa([pi 1/3])
vpaN =
[ 3.1415926535897932384626433832795, 0.33333333333333333333333333333333]
doubleN = double(vpaN)
doubleN =
    3.1416    0.3333

Convert Symbolic Matrix to Double-Precision Matrix

Convert the symbolic numbers in matrix symM to double-precision numbers by using double.

a = sym(sqrt(2));
b = sym(2/3);
symM = [a b; a*b b/a]
symM =
[       2^(1/2),       2/3]
[ (2*2^(1/2))/3, 2^(1/2)/3]
doubleM = double(symM)
doubleM =
    1.4142    0.6667
    0.9428    0.4714

High-Precision Conversion

When converting symbolic expressions that suffer from internal cancelation or round-off errors, increase the working precision by using digits before converting the number.

Convert a numerically unstable expression Y with double. Then, increase precision to 100 digits by using digits and convert Y again. This high-precision conversion is accurate while the low-precision conversion is not.

Y = ((exp(sym(200)) + 1)/(exp(sym(200)) - 1)) - 1;
lowPrecisionY = double(Y)
lowPrecisionY =
digitsOld = digits(100);
highPrecisionY = double(Y) 
highPrecisionY =

Restore the old precision used by digits for further calculations.


Input Arguments

collapse all

Symbolic input, specified as a symbolic number, or a vector, matrix, or multidimensional array of symbolic numbers.

Version History

Introduced before R2006a