A = 10; B = 15; C = 18;
lcm_ABC = lcm(sym([A, B, C]));
lcm_ABC = double(lcm_ABC);
ABC_N = lcm_ABC/A + lcm_ABC/B + lcm_ABC/C;
ABC_N = 20;
lcm_ABC = 90;
%i want to write it(ABC_N/lcm_ABC) as (20/90) or if may possible to write using formula (2/9)

 채택된 답변

Star Strider
Star Strider 2016년 7월 26일

1 개 추천

Use the rats or rat functions, or format rat to display it as rational fractions in the Command Window.

댓글 수: 4

Tell me one thing more, how to convert stored value in variable to symbolic?
(ABC_N/lcm_ABC) as (20/90)
Using both the rats and rat functions (with sprintf for rat):
ABC_N = 20;
lcm_ABC = 90;
rs = rats(ABC_N/lcm_ABC,6) % Using ‘rats’
[rtn,rtd] = rat(ABC_N/lcm_ABC); % Using ‘rat’
rt = sprintf('%2.0f/%2.0f', rtn*10, rtd*10) % Display In Desired Format
rs =
2/9
rt =
20/90
These only affect the way the value is displayed. MATLAB retains full internal precision, so the result of this division, ‘(ABC_N/lcm_ABC)’, ‘rs’ in my code, will be stored as a double-precision floating-point value. The ‘rtn’ and ‘rtd’ values are also stored as double-precision numbers.
Triveni
Triveni 2016년 7월 26일
This was not my question actually...by the way lot of thanks. I want to know that if i have a variable ABC_N = 20; and lcm_ABC = 90; can i treat 20 and 90 as symbolic? how to write 20/90 using symbolic toolbox?
My pleasure.
I did not realise you were using the Symbolic Math Toolbox.
To use the Symbolic Math Toolbox, the best (perhaps the only) way is to use the sym function for each variable:
A = 10; B = 15; C = 18;
A = sym(A);
B = sym(B);
C = sym(C);
lcm_ABC = lcm([A, B, C]);
ABC_N = lcm_ABC/A + lcm_ABC/B + lcm_ABC/C;
All the results are then symbolic as well. This will produce the result you want.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품

태그

질문:

2016년 7월 26일

댓글:

2016년 7월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by