필터 지우기
필터 지우기

Factorization With Symbolic Terms

조회 수: 164 (최근 30일)
Giulio Cesare Mastrocinque Santo
Giulio Cesare Mastrocinque Santo 2018년 11월 24일
댓글: madhan ravi 2018년 11월 25일
Hello! Does any one knows how can I group a specific term in a long equation?
For example, imagine i have the equation , which is equivalent to .
If I use the factor function, I obtain:
syms x
eq = x^2 + 6*x + 9
factor(eq,x)
ans = [ x + 3, x + 3]
However, I want to group those terms inside the eq itself, so I can keep manipulating the symbolic expression (eq = (x+3)^2). I am asking these because I am solving a Lagrange equation and I need to group the terms in the forma (x + y) and (x - y). Once they are grouped, I want to make a variable change: subs(eq,(x+y),z) and subs(eq,(x-y),w).
Thanks a lot!

채택된 답변

Walter Roberson
Walter Roberson 2018년 11월 25일
simplify() can handle some cases. However it is not sophisticated so while it might find x^2+6*x+9 it will certainly not find x^2+6*x+11 = (x+3)^2+2
subs will also not dig out opportunities for substitution . subs(5*xx+5*yy,xx+yy,zz) will not notice the opportunity as it looks for exact node matches.
So generally you would proceed like
simplify(subs(TheExpression, y, z-x))

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 11월 24일
편집: madhan ravi 2018년 11월 25일
AFAIK - I don't think there is a possibility to do that in symbolic math toolbox
After all the struggles: see isequaln()
eq=x^2 + 6*x + 9
s=factor(eq)
if isequaln(s(1),s(2)) %assuming only two factors
result=s(1)*s(2);
else
result = s;
end
  댓글 수: 2
Giulio Cesare Mastrocinque Santo
Giulio Cesare Mastrocinque Santo 2018년 11월 25일
That works too! Thanks a lot for your answer!
madhan ravi
madhan ravi 2018년 11월 25일
Anytime :) , you can vote for the answer if it was helpful.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by