Hello everyone,

I am trying to simplify a symbolic expression (which is the result of the script below) but i am having trouble as it is pretty big and there are many parameters. My objective is to reorganize the expression "B" as powers of variables "c1" and "c2" with all the other parameters included in the coefficents of the polynomial expression (they are gonna be substitued by values in other calculations). I have tried with "simplify" and triyng to nest "collect" into one another.

Does anybody have any tips on how to make the process more efficient? Are there any functions, which I am not aware of right now, that can simplify polynomial expression with regards to the coefficients that multiply the different powers? how about with multivariable expressioon as is my case?

also, is there a way to make math expressions with powers, parentesis, fractions, etc. more readable in the command window? now i have the standard formatting setting of matlab which makes long expressions pretty hard to read

Thank you very much

K = [k1 + k2 + (k_a12+k_a21) k1*a1 - k2*a2 + (k_a21*a1 - k_a12*a2);

k1*a1 - k2*a2 + (k_a12*a1-k_a21*a2) k1*a1^2 + k2*a2^2 - (k_a12+k_a21)*a1*a2];

C = [c1 + c2 + (c_a12+c_a21) c1*a1 - c2*a2 + (c_a21*a1 - c_a12*a2);

c1*a1 - c2*a2 + (c_a12*a1-c_a21*a2) c1*a1^2 + c2*a2^2 - (c_a12+c_a21)*a1*a2];

det_K = simplify(collect(collect(collect(collect(det(K), 2*a1), a2), a1^2), a2^2));

det_C = simplify(collect(collect(collect(collect(det(C), 2*a1), a2), a1^2), a2^2));

Mat = (lambda^2)*M + lambda*C + K;

determinant = collect(det(Mat), lambda);

coeff = coeffs(determinant, lambda);

b0 = simplify(collect(collect(collect(collect(coeff(1), k_a12), k_a21), k2), k1))

b1 = simplify(collect(collect(collect(collect(coeff(2), 2*a1), a2), a1^2), a2^2))

b2 = simplify(collect(collect(collect(collect(collect(collect(coeff(3), m), J), c1), c2), c_a12), c_a21))

b3 = simplify(collect(collect(collect(collect(collect(collect(coeff(4), a1^2), a2^2), a1), a2), m), J))

B = b1*b2*b3 - b1^2 - b0*b3^2;

B = simplify(collect(B, c1))

this is B that i get:

(a1 + a2)^2*(m*(c1*a1^2 + (- c_a12 - c_a21)*a1*a2 + c2*a2^2) + J*(c1 + c2 + c_a12 + c_a21))*(c1*k2 + c2*k1 - c_a12*k_a21 - c_a21*k_a12)*(m*(a1^2*k1 + a2^2*k2 - a1*a2*k_a12 - a1*a2*k_a21) + J*(k1 + k2 + k_a12 + k_a21) + c1*c2*(a1 + a2)^2 - c_a12*c_a21*(a1 + a2)^2) - (a1 + a2)^2*(m*(c1*a1^2 + (- c_a12 - c_a21)*a1*a2 + c2*a2^2) + J*(c1 + c2 + c_a12 + c_a21))^2*(k1*k2 - k_a12*k_a21) - (a1 + a2)^4*(c1*k2 + c2*k1 - c_a12*k_a21 - c_a21*k_a12)^2