How do I solve a determinant in MATLAB?

Rook picture Rook · Nov 10, 2009 · Viewed 13.3k times · Source

As a simple example, let's say you have this matrix:

M = [omega 1;
     2     omega];

and you need to solve for the values of omega that satisfy the condition det M = 0. How do you do this in MATLAB?

It is surely something simple, but I haven't found the function yet.

Answer

gnovice picture gnovice · Nov 10, 2009

For the general case where your matrix could be anything, you would want to create a symbolic representation of your matrix, compute the determinant, and solve for the variable of interest. You can do this using, respectively, the functions SYM, DET, and SOLVE from the Symbolic Math Toolbox:

>> A = sym('[w 1; 2 w]');  % Create symbolic matrix
>> solve(det(A),'w')       % Solve the equation 'det(A) = 0' for 'w'

ans =

  2^(1/2)
 -2^(1/2)

>> double(ans)             % Convert the symbolic expression to a double

ans =

    1.4142
   -1.4142

There are also different ways to create the initial matrix A. Above, I did it with one string expression. However, I could instead use SYMS to define w as a symbolic variable, then construct a matrix as you normally would in MATLAB:

syms w
A = [w 1; 2 w];

and now A is a symbolic matrix just as it was in the first example.