Super user friendly output for equations

17 views (last 30 days)
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
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
qazedx
qazedx on 13 Mar 2011
there is one problem when I pasted your code matlab returned error
??? Undefined function or method 'pretty' for input arguments of type
'double'.
it was when you used pretty(xval)
in general I think this is what I need
Walter Roberson
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.

Sign in to comment.

More Answers (2)

qazedx
qazedx on 13 Mar 2011
there is one problem when I pasted your code matlab returned error ??? Undefined function or method 'pretty' for input arguments of type 'double'. it was when you used pretty(xval) in general I think this is what I need

qazedx
qazedx on 14 Mar 2011
that is what matlab shows to me: http://i44.photobucket.com/albums/f12/qazedx/Untitled.jpg

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!