I have a symbolic expression from simplify which has obvious cancellations and other further simplifications: how do I force this?

조회 수: 20 (최근 30일)
I have an expression:
A_1 =
A_1=simplify(A_1) gives:
A_1 =
Clearly the factor on the bottom should cancel with the same factor inside the square root. Also the factor on the "middle" line should come outside the square root without the square. Lastly I have defined a separate variable l_13 = sqrt(x_3^2+y_3^2): so I would also like to extract this from the square root as l_13. In this case I can see what needs to be done. However, ideally "simplify" would do it for me. Can I guide "simplify" somehow?
The full code (not necessarily set out the best) to get to the above is given below.
Thanks in advnace for any help.
syms x_2 x_3 x_4 y_3 y_4 l_13 l_34 x_f y_f
A=[
x_3/l_13, (x_4-x_3)/l_34
y_3/l_13, (y_4-y_3)/l_34]
b=[x_3-x_2; y_3]
t=A\b
x_f=x_2+(x_3/l_13)*t(1)
y_f=(y_3/l_13)*t(1)
syms x_e
x_e=x_3+(y_3/y_4)*(x_2-x_4)
syms x_BF y_BF x_AB x_BE L_BF L_AB L_BE
x_BF=x_f-x_2
y_BF=y_f
x_AB=x_2
x_BE=x_e-x_2
L_BF=sqrt(x_BF^2+y_BF^2)
L_AB=x_AB
L_BE=x_BE
syms A_1
A_1=L_AB*L_BF/L_BE
A_1 = simplify(A_1)

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 16일
Clearly the factor on the bottom should cancel with the same factor inside the square root.
syms x
f = sqrt(x^2)/x
f = 
sf = simplify(f)
sf = 
subs(sf,x,5)
ans = 
1
subs(sf,x,-5)
ans = 
simplify(subs(sf,x,5-1i))
ans = 
1
simplify(subs(sf,x,-5+1i))
ans = 
limit(sf,x,0)
ans = 
NaN
According to your logic, all of those results should have come out as 1.
You can force things:
ssf = simplify(f, 'ignoreanalytic', true)
ssf = 
1
but will you get the right answer?
  댓글 수: 1
Hugh Stone
Hugh Stone 2021년 8월 17일
Thank you for your help - I understand the point you are making which is very valid. In my case though I am happy to proceed: the factor is >0.

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

추가 답변 (1개)

Paul
Paul 2021년 8월 18일
Sometimes you can get furhter along by putting assumptions on the variables that reflect what they actually represent. For example, I've made some assumptions in your code below that all variables are real and certain algebraic combinations of varaibles are positive. I don't know if these assumptions actually reflect the problem at hand, but maybe you'll find them useful as examples for the your situation.
syms x_2 x_3 x_4 y_3 y_4 l_13 l_34 x_f y_f real
A=[
x_3/l_13, (x_4-x_3)/l_34
y_3/l_13, (y_4-y_3)/l_34];
b=[x_3-x_2; y_3];
t=A\b;
x_f=x_2+(x_3/l_13)*t(1);
y_f=(y_3/l_13)*t(1);
syms x_e
x_e=x_3+(y_3/y_4)*(x_2-x_4);
syms x_BF y_BF x_AB x_BE L_BF L_AB L_BE real
x_BF=x_f-x_2;
y_BF=y_f;
x_AB=x_2;
x_BE=x_e-x_2;
L_BF=sqrt(x_BF^2+y_BF^2);
L_AB=x_AB;
L_BE=x_BE;
syms A_1 real
A_1=L_AB*L_BF/L_BE;
A_1 = simplify(A_1)
A_1 = 
assume(x_3*y_4 - x_4*y_3 > 0);
A_1 = simplify(A_1)
A_1 = 
assume(x_2*y_3 - x_2*y_4 + x_3*y_4 - x_4*y_3 > 0);
A_1 = simplify(A_1)
A_1 = 

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by