Rook
Rook

Reputation: 62538

How do I solve a determinant in MATLAB?

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.

Upvotes: 3

Views: 14232

Answers (3)

user85109
user85109

Reputation:

If you don't have the symbolic toolbox, then use the sympoly toolbox, found on the file exchange.

sympoly omega
roots(det([omega 1;2 omega]))
ans =
      -1.4142
       1.4142

Upvotes: 2

gnovice
gnovice

Reputation: 125864

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.

Upvotes: 13

monksy
monksy

Reputation: 14234

Well the determinate is: om * om - 1*2 = 0

So you would get: om*om = 2

The formal definition is: [a b ; c d] = ad - bc

I would look into simplifying the determinate, and finding a solver to solve for the unknowns.

Upvotes: 0

Related Questions