Line | |
---|
1 | function d = det(X) |
---|
2 | %DET (overloaded) |
---|
3 | |
---|
4 | % Author Johan Löfberg |
---|
5 | % $Id: det.m,v 1.4 2006/07/26 20:17:57 joloef Exp $ |
---|
6 | |
---|
7 | n = X.dim(1); |
---|
8 | m = X.dim(2); |
---|
9 | |
---|
10 | if n~=m |
---|
11 | error('Matrix must be square.'); |
---|
12 | else |
---|
13 | switch n |
---|
14 | case 1 |
---|
15 | d = X; |
---|
16 | case 2 |
---|
17 | % Freakin overloading on multiplication doesn't work. Probalby |
---|
18 | % stupid code... |
---|
19 | Y1.type = '()'; |
---|
20 | Y2.type = '()'; |
---|
21 | Y3.type = '()'; |
---|
22 | Y4.type = '()'; |
---|
23 | Y1.subs = {1,1}; |
---|
24 | Y2.subs = {2,2}; |
---|
25 | Y3.subs = {1,2}; |
---|
26 | Y4.subs = {2,1}; |
---|
27 | d = subsref(X,Y1)*subsref(X,Y2)-subsref(X,Y3)*subsref(X,Y4); |
---|
28 | otherwise |
---|
29 | d = 0; |
---|
30 | Y.type = '()'; |
---|
31 | for i = 1:n |
---|
32 | Y.subs = {i,1}; |
---|
33 | xi = subsref(X,Y); |
---|
34 | if ~isequal(xi,0) |
---|
35 | Y.subs = {[1:1:i-1 i+1:1:n],2:n}; |
---|
36 | subX = subsref(X,Y); |
---|
37 | d = d + (-1)^(i+1)*xi*det(subX); |
---|
38 | end |
---|
39 | end |
---|
40 | end |
---|
41 | end |
---|
42 | % Reset info about conic terms |
---|
43 | d.conicinfo = [0 0]; |
---|
Note: See
TracBrowser
for help on using the repository browser.