Search code examples
matlabmatrixcoefficients

Matlab how to define coefficients in a matrix to compute the roots of a polynomial


I want to solve the coefficients of this equation in matlab in a matrix. E + 1/2x^3 - 1/4X^5 -1/4 = 0, where E = 1 and 1/16 So far have I got this. But it doesn't work.

if E < 1/8
        coeffs = [E + 1/2 - 1/4 1 0 -1/4];
        sols = roots(coeffs);
        sols = sort(sols,'descend');
        Y = sols(1);
        Z = sols(2);
    else E > 1/8;
        coeffs = [E + 1/2 - 1/4 2 1 0 -1/4];
        sols = roots(coeffs);
        sols = sort(sols,'descend');
        Y = sols(3);
        Z = sols(4);
    end

(Where Y and Z are limits of an integral I'm computing later on in the code.)

Where am I going wrong with this? I don't know how to get the coeffs=[] line right.


Solution

  • I assume you are trying to compute the roots of the following polynomial: (-1/4)x^5 + (0)x^4 + (E+1/2)x^3 + (0)x^2 + (0)x + (-1/4) = 0 This is important to clarify. If my assumption is correct, coeffs = [(-1/4) 0 (E+1/2) 0 0 (-1/4)]