views:

814

answers:

3

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.

A: 

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

So you would get: om*om = 2

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

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

monksy
Yes, obviously. But the above given is just an example. I don't have such a trivial case in my problem.
ldigas
+8  A: 

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.

gnovice
I didn't know about the symbolic matrices... that's pretty cool. You've got my vote.
monksy
steven <-- what he said. And exactly something I was hoping for ... ftw.
ldigas
Ugh, another matlabism... I am not entirely happy with this. I don't like that sym takes in a string rather than a matrix. That could cause some frustration down the road.
monksy
@steven: I addressed your concern somewhat with the recent edit to my answer. Also, if you are passing a numeric matrix to SYM, you don't need to pass it as a string. For example: `A = sym([1 1; 2 2])`
gnovice
+2  A: 

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
woodchips

related questions