Super user friendly output for equations
17 views (last 30 days)
Show older comments
Where I am studying no one knows how to use matlab and lecturers can't read it so I was wondering can matlab do something like this
a=4; b=5; c=6
>> x=a+b/c
x
4+5/6
>> eval(x)
x
....
and could I apply this to function pretty
Accepted Answer
Walter Roberson
on 12 Mar 2011
The "pretty" function is part of the symbolic toolbox. It looks to me as if you would want something like
syms a b c
x = a + b/c * 4 + sym('5/6');
pretty(x)
xval = subs(x, {a,b,c}, {4, 5, 6});
pretty(xval)
7 Comments
Walter Roberson
on 13 Mar 2011
But the parts above executed without trouble? That's odd. The result of subs() should have been a symbolic number. Please tell us what
class(subs(x, {a,b,c}, {4, 5, 6}))
returns, and make sure you do not use double() on the result of the subs() before you do that.
pretty() cannot be used by itself on a double-precision number: it *must* be used on a symbolic expression.
More Answers (2)
See Also
Categories
Find more on Symbolic Math Toolbox 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!