How to convert a string to a numeric (large decimal point number)

5 views (last 30 days)
Hello,
I am currently dealing with the conversion of a symbolic number with 32-digits, including the decimals. So for example, x = 8.7205519972788820837195089552552.
I need to pass in a DOUBLE of the size 3x1 into the fmincon() function for the initial 'X0' with this precision for my algorithm to work, and not a symbolic 3x1.
I tried using the vpa(x) function but it obviously returns a symbolic. The following code turns x into a string of the CHAR datatype. Is there a way I can convert str to a numeric (while keeping my 32-digit precision) and therefore a DOUBLE in case of multiple numbers in a vector of similar size to x?
x = vpa(x);
str = evalc('disp(x)');
If not, is there another way to work with atleast 32-digits precision? for example, is there a way to tell MATLAB to not round off numbers in between function calls?
Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 4 Nov 2020
Edited: Walter Roberson on 4 Nov 2020
No. fmincon is always going to make its judgements based on double precision and will always use double precision to predict new values.
You can do hacks such as using a vector of 14 x values in the range 0 to 255, and building your 107 bit number out of the 112 bits that would offer... but the movement is very likely to be discontinuous as far as those values are concerned, and that is not permitted by fmincon.
So instead work symbolically, vpasolve for diff(f^2,x)==0
If this is still the sum of squares problem then both formulations are going to struggle. There are tools for sum of squares problems such as SeDuMi but I do not know if they will help
  1 Comment
Tan Hoang
Tan Hoang on 6 Nov 2020
Yes, it is still the Sum of Squares problem that I posted prior to this post. I found that the Sum of squares functions in my code are indeed equal, but only when I use the vpa() function. That means that there is some rounding error which I still do not know how to fix.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!