Help with simplifying a complex symbolic expression

There is a symbolic expression, and one of the variable "U_j0" can be cancled out.
But when I use "simplify()" command, "U_j0" is still in the expression. Can anyone help me out to further simplify the expression below?
syms dIm Im dKm Km alpha1 omega1 S U1 delta c1 m
syms omega Omega R0 R Uinf U_j0
% The following is the symbolic expression waiting to be simplified. ^ O ^
% Thank you!
term1=((2*log(-(U_j0*(alpha1 - alpha1*c1 + S*delta*m))/delta)*(S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2) - (log(R)*(m^2 - 2))/m^2 + (Im*alpha1^2*((R*dIm*delta*((2*S*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2) - (log(-R*(delta - 1))*(m^2 - 2))/m^2 + (2*log(-(U_j0*alpha1*(c1 - 1)*(delta - 1))/delta)*(S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2)))/(Im*alpha1) - (R^2*delta^2*((U_j0*alpha1*(c1 - 1))/(R^2*delta*(delta - 1)) + (S*U_j0*m*((2*S*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2) - (log(-R*(delta - 1))*(m^2 - 2))/m^2 + (2*log(-(U_j0*alpha1*(c1 - 1)*(delta - 1))/delta)* (S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2)))/(R^2*delta*(delta - 1))))/(U_j0*alpha1^2*(c1 - 1)))*(c1 - 1)*(delta - 1))/(delta*(Im*S*m - R*alpha1*dIm + R*alpha1*c1*dIm + R*alpha1*dIm*delta - R*alpha1*c1*dIm*delta)) + (2*S*alpha1*(c1 - 1)*(delta - 1)*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2*(alpha1 - alpha1*c1 + S*delta*m)));
I tried to combine "log()" terms by hand and simplified the above expression to get a new one shown below (cancel variable "U_j0") , but the expression I got is not correct. I wondered anyone could help me to use MATLAB program to simplify this expression and cancel variable "U_j0"?

 Akzeptierte Antwort

Paul
Paul am 26 Mär. 2021
This code eliminates U_j0:
[num,den]=numden(term1);
newnum = combine(num,'log','IgnoreAnalyticConstraints',true);
newterm1 = newnum/den;

4 Kommentare

Lu Zhao
Lu Zhao am 26 Mär. 2021
This is brilliant! Thank you for helping me out. ^ - ^
Hi Paul,
Thank you the code. I have a follow-up question:
If substitute the variables with numbers for two expressions, then the answers supposed to be equal. However, command "subs()" gives two different values. Is there any beter way to check on results?
syms dIm Im dKm Km alpha1 omega1 S U1 delta c1 m
syms omega Omega R0 R Uinf U_j0
% The following is the symbolic expression waiting to be simplified. ^ O ^
% Thank you!
term1=((2*log(-(U_j0*(alpha1 - alpha1*c1 + S*delta*m))/delta)*(S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2) - (log(R)*(m^2 - 2))/m^2 + (Im*alpha1^2*((R*dIm*delta*((2*S*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2) - (log(-R*(delta - 1))*(m^2 - 2))/m^2 + (2*log(-(U_j0*alpha1*(c1 - 1)*(delta - 1))/delta)*(S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2)))/(Im*alpha1) - (R^2*delta^2*((U_j0*alpha1*(c1 - 1))/(R^2*delta*(delta - 1)) + (S*U_j0*m*((2*S*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2) - (log(-R*(delta - 1))*(m^2 - 2))/m^2 + (2*log(-(U_j0*alpha1*(c1 - 1)*(delta - 1))/delta)* (S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2)))/(R^2*delta*(delta - 1))))/(U_j0*alpha1^2*(c1 - 1)))*(c1 - 1)*(delta - 1))/(delta*(Im*S*m - R*alpha1*dIm + R*alpha1*c1*dIm + R*alpha1*dIm*delta - R*alpha1*c1*dIm*delta)) + (2*S*alpha1*(c1 - 1)*(delta - 1)*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2*(alpha1 - alpha1*c1 + S*delta*m)));
[num,den]=numden(term1);
newnum = combine(num,'log','IgnoreAnalyticConstraints',true);
newterm1 = newnum/den;
% Double-check :
Y1 = subs(term1,[alpha1,c1,S,delta,m, R,U_j0],[1,0.1,1,0.1,1,1,1])
Y3 = subs(newterm1,[alpha1,c1,S,delta,m, R],[1,0.1,1,0.1,1,1])
simplify(Y3-Y1) % The value is not zero. Did I miss anything?
Im and dIm are left over in Y3 - Y1. Substitute values in for those too:
>> Y1 = subs(term1,[alpha1,c1,S,delta,m, R, Im, dIm, U_j0],[1,0.1,1,0.1,1,1,3,2,1]);
>> Y3 = subs(newterm1,[alpha1,c1,S,delta,m, R, Im , dIm],[1,0.1,1,0.1,1,1,3,2]);
>> simplify(Y1-Y3,500)
ans =
0
Here is the code I used to show that num and newnum are identical (ignoring the Analytic Constraints):
>> syms dIm Im dKm Km alpha1 omega1 S U1 delta c1 m
syms omega Omega R0 R Uinf U_j0
% The following is the symbolic expression waiting to be simplified. ^ O ^
% Thank you!
term1=((2*log(-(U_j0*(alpha1 - alpha1*c1 + S*delta*m))/delta)*(S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2) - (log(R)*(m^2 - 2))/m^2 + (Im*alpha1^2*((R*dIm*delta*((2*S*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2) - (log(-R*(delta - 1))*(m^2 - 2))/m^2 + (2*log(-(U_j0*alpha1*(c1 - 1)*(delta - 1))/delta)*(S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2)))/(Im*alpha1) - (R^2*delta^2*((U_j0*alpha1*(c1 - 1))/(R^2*delta*(delta - 1)) + (S*U_j0*m*((2*S*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2) - (log(-R*(delta - 1))*(m^2 - 2))/m^2 + (2*log(-(U_j0*alpha1*(c1 - 1)*(delta - 1))/delta)* (S^2*m^2 + 2*S*alpha1*c1*m - 2*S*alpha1*m - alpha1^2*c1^2 + 2*alpha1^2*c1 - alpha1^2))/(m^2*(alpha1 + S*m - alpha1*c1)^2)))/(R^2*delta*(delta - 1))))/(U_j0*alpha1^2*(c1 - 1)))*(c1 - 1)*(delta - 1))/(delta*(Im*S*m - R*alpha1*dIm + R*alpha1*c1*dIm + R*alpha1*dIm*delta - R*alpha1*c1*dIm*delta)) + (2*S*alpha1*(c1 - 1)*(delta - 1)*(S*m - alpha1 + alpha1*c1))/(m*(alpha1 + S*m - alpha1*c1)^2*(alpha1 - alpha1*c1 + S*delta*m)));
[num,den]=numden(term1);
newnum = combine(num,'log','IgnoreAnalyticConstraints',true);
>> simplify(combine(newnum-num,'log','IgnoreAnalyticConstraints',true),500)
ans =
0
It may be possible to get simpler expressions by putting appropriate assumptions (e.g., real, positive, etc.) on the variables if appropriate.
Lu Zhao
Lu Zhao am 29 Mär. 2021
That is great! I learned a lot from it. Than you. I really appreciate it. : D

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 26 Mär. 2021

Kommentiert:

am 29 Mär. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by