Formatting Matlab's output to Command Window

16 vues (au cours des 30 derniers jours)
Aarjav Khara
Aarjav Khara le 3 Déc 2020
I am trying to check a few symbolic equations by printing them to the Command Window. My Command Window prefrences are already defaulted to "short" output format for numeric values and doesn't give any issue when printing numeric values to the command window. However, when trying to display a symbolic equation, for example:
equation = (-66*cos( th1 + pi/2 ) - 0.99*x*cos( th1 + pi/2 ) + 0.99*y*sin( th1 + pi/2 )) / (cos( th1 + pi/2 )^2 + sin( th1 + pi/2 )^2 )
By simply using the disp(simplify(equation)) command, the following is printed to the Command Window:
-(222143115238362815690920839645245649785771639010720389686529839575*cos(th11 + pi/2) + 3291009114642412084309938365114701009965471731267159726697218048*x0*cos(th11 + pi/2) - 3291009114642412084309938365114750367196616874232894662022664290*y0*sin(th11 + pi/2))/(3291009114642412084309938365114750367196616874232894662022664290*(cos(th11 + pi/2)^2 + sin(th11 + pi/2)^2))
So, I tried using vpa(equation,2) to display the numerical values to 2 significant digits, the output is:
-(3.0e-64*(2.2e+65*cos(th11 + 1.6) + 3.3e+63*x0*cos(th11 + 1.6) - 3.3e+63*y0*sin(th11 + 1.6)))/(cos(th11 + 1.6)^2 + sin(th11 + 1.6)^2)
Is there a way to change the output format of the Command Window so that it shows the equation so that it is human reader friendly?

Réponse acceptée

Ameer Hamza
Ameer Hamza le 3 Déc 2020
Modifié(e) : Ameer Hamza le 3 Déc 2020
The format short only applies to native numeric datatypes, e.g., double. Generally, it is preferable to display symbolic calculation in full precision. However, you can change the default display of symbolic numbers using sympref()
sympref('FloatingPointOutput', 1)
It will change the preference of symbolic toolbox to display values as floating point numbers. To revert back, run
sympref('FloatingPointOutput', 0)
  2 commentaires
Deepak Gupta
Deepak Gupta le 3 Déc 2020
Modifié(e) : Walter Roberson le 3 Déc 2020
Adding to Ameer's answer.
For more info on this you can follow the documentation:
Aarjav Khara
Aarjav Khara le 3 Déc 2020
Thank you!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Functions dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by