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.