Last change
on this file since 17 was
17,
checked in by zhangj, 10 years ago
|
To have a stable version on the server.
|
-
Property svn:executable set to
*
|
File size:
857 bytes
|
Line | |
---|
1 | function spd=det(sp) |
---|
2 | % sympoly/det: determinant of a (square) sympoly array |
---|
3 | % usage: spd=det(sp); |
---|
4 | % |
---|
5 | % arguments: |
---|
6 | % sp - square matrix sympoly object |
---|
7 | % |
---|
8 | % spd - scalar sympoly object containing the determinant |
---|
9 | |
---|
10 | s=size(sp); |
---|
11 | if s(1)~=s(2) |
---|
12 | error 'Must be a square array for the determinant' |
---|
13 | end |
---|
14 | |
---|
15 | n=s(1); |
---|
16 | switch n |
---|
17 | case 1 |
---|
18 | % 1x1 |
---|
19 | spd=sp; |
---|
20 | |
---|
21 | case 2 |
---|
22 | % 2x2 |
---|
23 | spd=sp(1,1).*sp(2,2)-sp(1,2).*sp(2,1); |
---|
24 | |
---|
25 | case 3 |
---|
26 | % 3x3 |
---|
27 | spd = sp(1,1).*sp(2,2).*sp(3,3) + sp(1,2).*sp(2,3).*sp(3,1) ... |
---|
28 | + sp(1,3).*sp(2,1).*sp(3,2) - sp(3,1).*sp(2,2).*sp(1,3) ... |
---|
29 | - sp(3,2).*sp(2,3).*sp(1,1) - sp(3,3).*sp(2,1).*sp(1,2); |
---|
30 | |
---|
31 | otherwise |
---|
32 | % 4x4 and higher, use minors to compute the |
---|
33 | % determinant recursively |
---|
34 | spd=0; |
---|
35 | minorsigns = 1; |
---|
36 | for i=1:n |
---|
37 | j=1:n; |
---|
38 | j(i)=[]; |
---|
39 | spd = spd + minorsigns.*sp(i,1).*det(sp(j,2:n)); |
---|
40 | minorsigns = -minorsigns; |
---|
41 | end |
---|
42 | |
---|
43 | end |
---|
44 | |
---|
Note: See
TracBrowser
for help on using the repository browser.