Symbolic to double or very precise

2 ビュー (過去 30 日間)
Jithin D Mathew
Jithin D Mathew 2020 年 11 月 24 日
コメント済み: Ameer Hamza 2020 年 11 月 24 日
Hi, I have an array like this
final_lst= [ 3.926602312047918778238533343627, 7.0685827456287320885529589275467, 10.210176122813030545468205594657, 13.351768777754093124209703822879, 16.493361431346409780773598432419, 19.634954084936207731575034033848, 22.776546738526000978837700244001, 25.918139392115794217316777165947, 29.059732045705587455779451237919, 32.201324699295380694242094678508]
It is a symbolic array. I need to make it a double precision number or any number type with the most number of values after decimal places. If I use eval, then it returns only 4 places after decimal. I need as much digits after decimal as possible and I need it to be in a normal array. Could someone help ?

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 24 日
Among the natively supported datatype, double() will provide most precision. You can convert a vector from symbolic to double using double()
double(final_lst)
Note that the display in command window is not same as how the number is stored in memory. For example, If you want to see more number after decimal point, you can just use
format long
double(final_lst)
  2 件のコメント
Rik
Rik 2020 年 11 月 24 日
To further illustrate the point Ameer is making:
str='3.926602312047918778238533343627';
final_lst=sym(str);
fprintf('%s - sym \n',str),fprintf('%.30f - double \n',double(final_lst)),fprintf('%.30f - eps \n',eps(double(final_lst)))
3.926602312047918778238533343627 - sym
3.926602312047918985626893118024 - double
0.000000000000000444089209850063 - eps
Ameer Hamza
Ameer Hamza 2020 年 11 月 24 日
@Rik, Thanks for further illustrating the point.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by