Display symbolic expressions as rational.

31 visualizaciones (últimos 30 días)
Agustín Rico
Agustín Rico el 2 de Feb. de 2021
Comentada: Robert Ukrow el 26 de En. de 2022
How can I display symbolic expressions as rationals? Functions like sympref or vpa allows to display in decimal format, but doesn't provide a way to display symbolic expressions as rationals.
For example:
syms x
(1/2)*(3*x^2)
ans =
1.5000*x^2
Instead of that output I desire the rational expression (or similar):
(3*x^2)/2
  1 comentario
James Tursa
James Tursa el 2 de Feb. de 2021
That's what I get:
>> syms x
(1/2)*(3*x^2)
ans =
(3*x^2)/2
Do you have something set in preferences that is forcing the decimal output?

Iniciar sesión para comentar.

Respuesta aceptada

madhan ravi
madhan ravi el 2 de Feb. de 2021
Editada: madhan ravi el 2 de Feb. de 2021
syms x
sympref('FloatingPointOutput',true);
(1/2)*(3*x^2)
ans = 
sympref('FloatingPointOutput',false);
(1/2)*(3*x^2)
ans = 
  3 comentarios
Diaa
Diaa el 18 de Dic. de 2021
Thanks to you for this answer, and special thanks to google algorithm for bringing me here without wasting my whole day.
Robert Ukrow
Robert Ukrow el 26 de En. de 2022
Had the same problem and it worked..thanks !

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by