Symbolic expression simplification and shortening

1 visualización (últimos 30 días)
SM
SM el 4 de Jun. de 2024
Respondida: Star Strider el 4 de Jun. de 2024
I have an extremely long symbolic expression after simplification which I am unable to simplify further. I want to know how to reduce the expression further, or to find repeating sub expressions inside the expression which can be replaced by another variable?
For an example, my expression looks somewhat like this:
U =
108*A^2*e^7*e1^3*e2^7*h2^4 + 153*A^2*e^7*e1^5*e2^7*h2^2 + 108*A^2*e^7*e1^7*e2^3*h3^4 + 153*A^2*e^7*e1^7*e2^5*h3^2 +...
24*B^2*e^3*e1^7*e2^7*h1^4 + 95*B^2*e^5*e1^7*e2^7*h1^2 + 24*B^2*e^7*e1^3*e2^7*h2^4 + 95*B^2*e^7*e1^5*e2^7*h2^2 + ...
24*B^2*e^7*e1^7*e2^3*h3^4 + 95*B^2*e^7*e1^7*e2^5*h3^2 + 9*A^2*e^2*e1^7*h1^5*h3^7 + 9*A^2*e^2*e2^7*h1^5*h2^7 +...
9*A^2*e1^2*e2^7*h1^7*h2^5 + 9*A^2*e^7*e1^2*h2^5*h3^7 + 9*A^2*e^7*e2^2*h2^7*h3^5 + 9*A^2*e1^7*e2^2*h1^7*h3^5 -...
41*B^2*e^2*e1^7*h1^5*h3^7 - 41*B^2*e^2*e2^7*h1^5*h2^7 - 12*B^2*e^4*e1^7*h1^3*h3^7 - 12*B^2*e^4*e2^7*h1^3*h2^7 -....
41*B^2*e1^2*e2^7*h1^7*h2^5 - 12*B^2*e1^4*e2^7*h1^7*h2^3 - 41*B^2*e^7*e1^2*h2^5*h3^7 - 12*B^2*e^7*e1^4*h2^3*h3^7 - ...
41*B^2*e^7*e2^2*h2^7*h3^5 - 12*B^2*e^7*e2^4*h2^7*h3^3 - 41*B^2*e1^7*e2^2*h1^7*h3^5 - 12*B^2*e1^7*e2^4*h1^7*h3^3 -...
504*A^2*e^3*h1^4*h2^7*h3^7 + 9*A^2*e^5*h1^2*h2^7*h3^7 - 504*A^2*e1^3*h1^7*h2^4*h3^7 + 9*A^2*e1^5*h1^7*h2^2*h3^7 -...
504*A^2*e2^3*h1^7*h2^7*h3^4 + 9*A^2*e2^5*h1^7*h2^7*h3^2 + 2860*B^2*e^3*h1^4*h2^7*h3^7 - 377*B^2*e^5*h1^2*h2^7*h3^7 +...
2860*B^2*e1^3*h1^7*h2^4*h3^7 - 377*B^2*e1^5*h1^7*h2^2*h3^7 + 2860*B^2*e2^3*h1^7*h2^7*h3^4 - 377*B^2*e2^5*h1^7*h2^7*h3^2 +...
162*A*B*e^7*e1^7*e2^7 - 6*A*B*e^7*h2^7*h3^7 - 6*A*B*e1^7*h1^7*h3^7 - 6*A*B*e2^7*h1^7*h2^7 + 1944*A^2*e*h1^6*h2^7*h3^7 + ...
1944*A^2*e1*h1^7*h2^6*h3^7 + 1944*A^2*e2*h1^7*h2^7*h3^6 - 5400*B^2*e*h1^6*h2^7*h3^7 - 5400*B^2*e1*h1^7*h2^6*h3^7 -...
245*B^2*e^6*e1^7*e2^4*h1*h3^3 + 147*B^2*e^7*e1*e2^3*h2^6*h3^4 + 48*B^2*e^7*e1*e2^5*h2^6*h3^2 - 60*B^2*e^7*e1^2*e2^6*h2^5*h3 + ...
147*B^2*e^7*e1^3*e2*h2^4*h3^6 - 245*B^2*e^7*e1^4*e2^6*h2^3*h3 + 48*B^2*e^7*e1^5*e2*h2^2*h3^6 - 60*B^2*e^7*e1^6*e2^2*h2*h3^5 -...
where e , e1, e2, h1, h2, h3, A, B are the symbolic variables.

Respuesta aceptada

Star Strider
Star Strider el 4 de Jun. de 2024
The expression is apparently incomplete.
Working with what is provided —
syms e e1 e2 h1 h2 h3 A B
U = 108*A^2*e^7*e1^3*e2^7*h2^4 + 153*A^2*e^7*e1^5*e2^7*h2^2 + 108*A^2*e^7*e1^7*e2^3*h3^4 + 153*A^2*e^7*e1^7*e2^5*h3^2 +...
24*B^2*e^3*e1^7*e2^7*h1^4 + 95*B^2*e^5*e1^7*e2^7*h1^2 + 24*B^2*e^7*e1^3*e2^7*h2^4 + 95*B^2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3^7 + ...
1944*A^2*e1*h1^7*h2^6*h3^7 + 1944*A^2*e2*h1^7*h2^7*h3^6 - 5400*B^2*e*h1^6*h2^7*h3^7 - 5400*B^2*e1*h1^7*h2^6*h3^7 -...
245*B^2*e^6*e1^7*e2^4*h1*h3^3 + 147*B^2*e^7*e1*e2^3*h2^6*h3^4 + 48*B^2*e^7*e1*e2^5*h2^6*h3^2 - 60*B^2*e^7*e1^2*e2^6*h2^5*h3 + ...
147*B^2*e^7*e1^3*e2*h2^4*h3^6 - 245*B^2*e^7*e1^4*e2^6*h2^3*h3 + 48*B^2*e^7*e1^5*e2*h2^2*h3^6 - 60*B^2*e^7*e1^6*e2^2*h2*h3^5
U = 
U = simplify(U, 1000) % It May Not Simplify Further
U = 
Ukids = children(U) % Return Sub-Expressions
Ukids = 1x57 cell array
Columns 1 through 7 {[108*A^2*e^7*e1...]} {[153*A^2*e^7*e1...]} {[108*A^2*e^7*e1...]} {[153*A^2*e^7*e1...]} {[24*B^2*e^3*e1^...]} {[95*B^2*e^5*e1^...]} {[24*B^2*e^7*e1^...]} Columns 8 through 14 {[95*B^2*e^7*e1^...]} {[24*B^2*e^7*e1^...]} {[95*B^2*e^7*e1^...]} {[9*A^2*e^2*e1^7...]} {[9*A^2*e^2*e2^7...]} {[9*A^2*e1^2*e2^...]} {[9*A^2*e^7*e1^2...]} Columns 15 through 21 {[9*A^2*e^7*e2^2...]} {[9*A^2*e1^7*e2^...]} {[-41*B^2*e^2*e1...]} {[-41*B^2*e^2*e2...]} {[-12*B^2*e^4*e1...]} {[-12*B^2*e^4*e2...]} {[-41*B^2*e1^2*e...]} Columns 22 through 28 {[-12*B^2*e1^4*e...]} {[-41*B^2*e^7*e1...]} {[-12*B^2*e^7*e1...]} {[-41*B^2*e^7*e2...]} {[-12*B^2*e^7*e2...]} {[-41*B^2*e1^7*e...]} {[-12*B^2*e1^7*e...]} Columns 29 through 35 {[-504*A^2*e^3*h...]} {[9*A^2*e^5*h1^2...]} {[-504*A^2*e1^3*...]} {[9*A^2*e1^5*h1^...]} {[-504*A^2*e2^3*...]} {[9*A^2*e2^5*h1^...]} {[2860*B^2*e^3*h...]} Columns 36 through 42 {[-377*B^2*e^5*h...]} {[2860*B^2*e1^3*...]} {[-377*B^2*e1^5*...]} {[2860*B^2*e2^3*...]} {[-377*B^2*e2^5*...]} {[162*A*B*e^7*e1...]} {[-6*A*B*e^7*h2^...]} Columns 43 through 49 {[-6*A*B*e1^7*h1...]} {[-6*A*B*e2^7*h1...]} {[1944*A^2*e*h1^...]} {[1944*A^2*e1*h1...]} {[1944*A^2*e2*h1...]} {[-5400*B^2*e*h1...]} {[-5400*B^2*e1*h...]} Columns 50 through 56 {[-245*B^2*e^6*e...]} {[147*B^2*e^7*e1...]} {[48*B^2*e^7*e1*...]} {[-60*B^2*e^7*e1...]} {[147*B^2*e^7*e1...]} {[-245*B^2*e^7*e...]} {[48*B^2*e^7*e1^...]} Column 57 {[-60*B^2*e^7*e1...]}
% for k1 = 1:numel(Ukids) % Symbolic Version Of The 'unique' Function
% Test = Ukids(k);
% for k2 = k1:numel(Ukids)
% Check(k1) = isAlways(Test == Ukids{k2});
% end
% end
% Check
Using the children function, it returns 57 apparently unique substrings (I did not check all of them with the commented-out loops, since the unique function does not work with symbolic objects).
So that may be the best you can do. As to whether they can be replaced by specific symbolic variables or symbolic fucntions, perhaps yes. I defer to you for that experiment, using the subs function.
.

Más respuestas (0)

Categorías

Más información sobre Formula Manipulation and Simplification en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by