What codes can be used to retain the decimals before the defined symbolic variable
3 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
I want to ask, what codes can be used to retain the decimals before the defined symbolic variable? For instance, a symbolic result
0.0029068360163364559412002563476562*dis_r1 - 0.005666737824361646885806820250764*dis_r2 + 0.056999838488600009997475659418*dis_r3 – 0.001770474043114554640876434632446*dis_t2 - 0.045184740924660363181608602189954*dis_t3 + 6.4455841527204101204420278888018e-37*for_q1 - 0.03001164382667592667175426868198*for_q2
has been obtained, where dis_r1, dis_r2, dis_r3, for_q1, and for_q2 are defined symbolic variables. I want to keep three decimals before them.
Many thanks!
1 件のコメント
Walter Roberson
2025 年 5 月 18 日
I am seeing oddities,
ttt = sym('0.0029068360163364559412002563476562')
length(char(ttt))
Except most of the time it returns something of length 104, or 136, but sometimes 36...
採用された回答
Sulaymon Eshkabilov
2025 年 5 月 18 日
Here is one of the viable options with digits() and vpa():
syms dis_r1 dis_r2 dis_r3 for_q1 for_q2
dis_t2 = 1;
dis_t3 = 2;
% Equation:
EQN = 0.0029068360163364559412002563476562*dis_r1 - 0.005666737824361646885806820250764*dis_r2 +...
0.056999838488600009997475659418*dis_r3 - 0.001770474043114554640876434632446*dis_t2 - ...
0.045184740924660363181608602189954*dis_t3 + 6.4455841527204101204420278888018e-37*for_q1 -...
0.03001164382667592667175426868198*for_q2;
% Solve the equation:
Solution = solve(EQN, dis_r1);
% Display the solution:
disp(Solution);
%% This is how to set up specific decimal places!
% Set the desired number of decimal places
Precision = 5; % The number of decimal places
digits(Precision); % Set the global precision
% Convert solution to variable precision:
VPA_Solution = vpa(Solution);
% Compare Solution vs. VPA_Solution
disp(VPA_Solution)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numbers and Precision についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!