how to expand/rewrite/simplify (cos(a)+cos(b))^2?
Show older comments
I have the code below. How to expand/rewrite/simplify the expression f^2 into cos(2a), cos(2b), cos(a+b), cos(2a), cos(2b), cos(a-b), cos(b-a)?
==========================================
syms a b;
f=cos(a)+cos(b);
combine(f^2)
shows (cos(a) + cos(b))^2
rewrite(f^2, 'sincos')
shows (cos(a) + cos(b))^2
simplify(f^2)
shows (cos(a) + cos(b))^2
==========================================
3 Comments
You can expand() to get a 'longer' form
syms a b;
f = cos(a) + cos(b);
expand(f^2)
I don't know exactly how you want to rewite it. From your question I understand that you want to get
But simply testing numerically you can see that
. So can you please elaborate on what you want your result to be, since I most likely misunderstood it.
g = cos(2*a) * cos(2*b) * cos(a+b) * cos(2*a) * cos(2*b) * cos(a-b) * cos(b-a);
test1 = eval(subs(f^2, [a b],[1 2]))
test2 = eval(subs(g, [a b],[1 2]))
cfy30
on 27 Jul 2023
I could be wrong, but I don't think this is possible. In the rewrite() documentation you can find a list of functions that can be replaced, but squares/powers are not (yet?) one of the options.
Still I want to mention that you can find multiple simplifications with the following Code:
syms a b
expr = cos(a) + cos(b);
simplify(expr,'Steps',15,'All',true)
Answers (0)
Categories
Find more on Statics and Dynamics 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!
