Simplify doesn't simplify the way I want it to

5 次查看(过去 30 天)
Simplify doesn't combine factors in large expressions and will try to make an expression positive even at the cost of additional terms. I am exporting large vectors into fortran and I want to make it as easy as possible to optimize, which means I want to reduce as many terms as possible in large expressions. Simplify is not doing this with the default settings. I have looked and can't find a solution to this problem. Can somebody point to a setting or function that will accomplish what I am asking?
phi1 = sym('phi1', 'real');
Phi = sym('Phi', 'real');
phi2 = sym('phi2', 'real');
F = sym('F', [1 4], 'real');
assumeAlso(phi1>=0 & phi1<2*pi & Phi>=0 & Phi<=pi & phi2>=0 & phi2<2*pi)
simplify((6^(1/2)*F(1)*sin(2*phi2)*sin(Phi)^2)/4 + (6^(1/2)*F(2)*sin(2*phi2)*sin(Phi)^2)/4 + (6^(1/2)*F(3)*sin(2*Phi)*cos(phi2))/4 + (6^(1/2)*F(4)*sin(2*Phi)*cos(phi2))/4)
simplify((6^(1/2)*F(1)*sin(2*phi2)*sin(Phi)^2)/4 + (6^(1/2)*F(2)*sin(2*phi2)*sin(Phi)^2)/4)
simplify(2*sin(phi2)^2 - 1)
simplify(1 - 2*sin(phi2)^2)
EDIT: I installed maple's matlab toolbox and it had what I wanted in simplify(a, constants) but was jank in a lot of respects.

采纳的回答

Tarunbir Gambhir
Tarunbir Gambhir 2021-1-28
By default, 'simplify' only performs one simplification step, and that is why some expressions, like the one in the question, are not fully reduced. However, you can get a better answer by forcing 'simplify' to perform more steps. Go through this section for more clarification.
In situations where increasing the number of steps does not work, I suggest you try alternate simplification functions. For example, in the third case, you can reduce '2*sin(phi2)^2 - 1' using the following:
combine(2*sin(phi2)^2 - 1, 'sincos')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by