Formatting Matlab's output to Command Window
18 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Ameer Hamza
on 3 Dec 2020
Edited: Ameer Hamza
on 3 Dec 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 Comments
Deepak Gupta
on 3 Dec 2020
Edited: Walter Roberson
on 3 Dec 2020
Adding to Ameer's answer.
For more info on this you can follow the documentation:
More Answers (0)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!