How to write variable to symbolic ?

2 visualizaciones (últimos 30 días)
Triveni
Triveni el 26 de Jul. de 2016
Comentada: Star Strider el 26 de Jul. de 2016
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)

Respuesta aceptada

Star Strider
Star Strider el 26 de Jul. de 2016
Use the rats or rat functions, or format rat to display it as rational fractions in the Command Window.
  4 comentarios
Triveni
Triveni el 26 de Jul. de 2016
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?
Star Strider
Star Strider el 26 de Jul. de 2016
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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by