Simplify doesn't simplify the way I want it to

조회 수: 8 (최근 30일)
Russell Marki
Russell Marki 2020년 4월 22일
댓글: Walter Roberson 2021년 1월 28일
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