MATLAB: Finding the roots of a third degree polynomial

algebraengineeringequationequation solvinghomeworklinear algebraMATLABmatrixmatrix manipulationpolynomialvariablevariables

I'd like to be able to solve the equation in such a way that all I need to do is modify in the original variables if I ever want to change the problem, but I can't seem to find an easy way to do this.
% Find the cubic equation for the principal stresses and determine them
% Original Matrix
sigma_x = 25; % all in MPa
Txy = 10;
Txz = 15;
sigma_y = 0;
Tyz = 0;
sigma_z = -20;
% Matrix to solve with stresses to solve for
syms sigma_p
sigma_xsolve = sigma_x - sigma_p;
sigma_ysolve = sigma_y - sigma_p;
sigma_zsolve = sigma_z - sigma_p;
% Matrix
sigma = [sigma_xsolve Txy Txz; Txy sigma_ysolve Tyz; Txz Tyz sigma_zsolve];
% Equation
Characteristic_equation = det(sigma);
% Find the roots

Best Answer

You can use solve()
Characteristic_equation = det(sigma);
sol = solve(Characteristic_equation, 'MaxDegree', 3)
Result
>> sol
sol =
2500/(9*((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3)) + ((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3) + 5/3
5/3 - ((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3)/2 - (3^(1/2)*(2500/(9*((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3)) - ((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3))*1i)/2 - 1250/(9*((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3))
5/3 - ((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3)/2 + (3^(1/2)*(2500/(9*((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3)) - ((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3))*1i)/2 - 1250/(9*((108^(1/2)*2005578125^(1/2)*1i)/108 + 91375/54)^(1/3))
If you want numeric values
>> double(sol)
ans =
32.3833 - 0.0000i
-24.9033 - 0.0000i
-2.4800 + 0.0000i
Related Question