How can I display a complex decimal result with actual precision value?

I am trying to do arithmetic calculation with a number e=0.015923-0.03179523i iteratively to generate an encryption key which is to be expected a high precision complex decimal number. After calculation, I got the result only upto 4 decimal digits. I tried digits() but problem is that the result displayed according to the number given in digits(). I want the result with actual precision value. Please help.

 Accepted Answer

The default display format, format short, displays numbers "Short, fixed-decimal format with 4 digits after the decimal point." But note that this has no impact on how the numbers are stored and computed, which is to double precision. Change your display format if you want to see more decimal places.
If you want to compute your complex number using higher precision than double precision, use Symbolic Math Toolbox.

5 Comments

Hey I checked Symbolic Math Toolbox and according to it digits() and vpa() functions are used to get the high precision decimal number. That I have already checked. The problem with this approach is that I am getting result as per given value in digits(). Is there any other method to get actual decimal number as result?
Converting a double precision value into a symbolic expression doesn't magically increase the precision. If you start with symbolic expressions the calculations may take longer (potentially significantly longer, depending on what exactly you're doing) but you would not necessarily be limited to double precision.
Use
sym('15923/10^6')-sym('3179523i/10^8')
to define your number. None of the straightforward input representations will convert to exact number of decimal places. Using rational numbers allows you to make a precise conversion, under the assumption that those really are exact values rather than the rounded versions of the values.
To maintain decimals properly you need to restrict your operations to addition, subtraction, multiplication, and decision, along with exponentials to an integer (which can be calculated by repeated multiplication.)
You might be interested in John D'Errico's file exchange contributions for variable precision arithmetic.

Sign in to comment.

More Answers (1)

format long
will display the full numeric precision of all values at the command line.

1 Comment

I tried format long also but it gave result only upto 15 decimal digits.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 3 Nov 2016

Commented:

on 9 Nov 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!