Symbolic simplification for pretty output
Show older comments
This is a crosspost from http://stackoverflow.com/questions/21512047/matlab-mupad-symbolic-simplification-for-pretty-output
I need to automatically simplify some symbolic expressions but the `simplify` function of matlab can't do everything i need.
Example:
simplify(expand((ax + bx)^2 + (ay + by)^2))
Which results in the output
ax^2 + 2*ax*bx + ay^2 + 2*ay*by + bx^2 + by^2
So i've tried to create my own rules to make the output prettier
function [ result ] = simplify_pretty( term )
read(symengine, 'simplify_pretty_rules.mu');
result = feval(symengine, 'Simplify', term, 'SelectRules = simplify_pretty_rules')
end
with "simplify_pretty_rules.mu"
simplify_pretty_rules := proc()
begin
[
Rule(#X^2 - 2 * #X * #Y + #Y^2, (#X - #Y)^2),
Rule(#X^2 + 2 * #X * #Y + #Y^2, (#X + #Y)^2)
]
end_proc:
This works for input like...
simplify_pretty(expand((ax + bx)^2 + (ay + by)^2))
...but when changed to...
simplify_pretty(expand(-(ax + bx)^2 - (ay + by)^2))
...it doesn't
So the questions is: Is it possible to create rules which work in (nearly) all situations? What am I doing wrong?
Answers (0)
Categories
Find more on Library Domains in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!