source: MML/trunk/machine/SOLEIL/common/toolbox/SymbolicPolynomials/SymbolicPolynomials/@sympoly/det.m @ 17

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 
1function 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
10s=size(sp);
11if s(1)~=s(2)
12  error 'Must be a square array for the determinant'
13end
14
15n=s(1);
16switch n
17case 1
18  % 1x1
19  spd=sp;
20 
21case 2
22  % 2x2
23  spd=sp(1,1).*sp(2,2)-sp(1,2).*sp(2,1);
24
25case 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 
31otherwise
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 
43end
44
Note: See TracBrowser for help on using the repository browser.