MATLAB: How to change symbolic displays to decimal displays

display decimal number

How do I display a symbolic expression as a decimal?

Best Answer

There are several ways to approximate a number or change the display in Symbolic Math Toolbox.
To approximate a numeric value in double precision, you can use the “double” function. For example:
val = double(sqrt(2))
1.4142
If your expression uses a symbolic variable, you can use the “vpa” function. “vpa” gives a numerical approximation to the value (32 digits by default). For example:
syms x
val = vpa(sqrt(2)*x)
1.4142135623730950488016887242097*x
Starting in R2019a, if you want the equivalent of format short in Symbolic Math Toolbox, you can use “sympref”. For example:
sympref('FloatingPointOutput',true)
syms x
val = sqrt(2)*x
1.4142*x
Setting this preference will display any number in fixed-decimal format with four digits after the decimal point. This preference does not approximate any symbolic number into floating-point precision, and hence you can still perform the exact symbolic computation. Note that setting this preference carries over successive MATLAB sessions, so you need to call “sympref('default')” to restore the original setting.