|
楼主 |
发表于 2011-10-20 21:20
|
显示全部楼层
回复 1 # sunminmin 的帖子
下面是自己写的程序,能达到要求。
请路过的看看,指点指点,让程序的编写更加规范些。- function [ ] = mychildmatrix( matrix )
- %MYCHILDMATRIX Summary of this function goes here
- % Detailed explanation goes here
- disp('初始矩阵的维数:')
- [ R, C ] = size( matrix )
- disp('初始矩阵的秩:')
- ofrank = rank( matrix )
- %childmatrix = nchoosek( R, ofrank) * nchoosek( R, ofrank);
- BMAT = cell( 280, 290 );
- CMAT = cell( 280, 290 );
- DMAT = cell( 280, 290 );
- CMAT{ 1, 1 } = matrix;
- UnlikeMatrixOfTotal = 0;
-
- for k = 1 : R - ofrank
- BMAT = CMAT;
- p = 1;
- q = 1;
- for j = 1 : 290
- for i = 1 : 280
- if BMAT{ i, j }
- midmat = BMAT{ i, j };
- sourcemat = midmat;
- [ midr, midc ] = size( BMAT{ i, j } );
- for m = 1 : midr
- for n = 1 : midc
- midmat( m, : ) = [];
- midval = midmat;
- midval( :, n ) = [];
- CMAT{ p, q } = midval;
- for y = 1 : q - 1
- for x = 1 : 280
- if isequal( CMAT{ x, y }, CMAT{ p, q })
- CMAT{ p, q } = [];
- end
- end
- end
- for x = 1 : p - 1
- if isequal( CMAT{ x, q }, CMAT{ p, q })
- CMAT{ p, q } = [];
- end
- end
-
- if CMAT{ p, q }
- p = p + 1;
- if p > 280
- p = 1;
- q = q + 1;
- end
- midmat = sourcemat;
- else midmat = sourcemat;
- end
- end
- end
- end
- end
- end
- end
-
- %去掉CMAT中重复的元素,得到matrix的rank(matrix)阶子式,即为所求。
- %因为采用的递归删除矩阵行列求矩阵的子式的思想会产生重复的子矩阵。
- for j = 1 : 290
- for i = 1 : 280
- if size( CMAT{ i, j } ) == [ ofrank, ofrank ]
- DMAT{ i, j } = CMAT{ i, j };
- end
- end
- end
-
- disp('初始矩阵的子矩阵为:')
- for j = 1 : 290
- for i = 1 : 280
- if DMAT{ i, j }
- disp( DMAT{ i, j })
- UnlikeMatrixOfTotal = UnlikeMatrixOfTotal + 1;
- else break;
- end
- end
- end
- maxdet = -inf;
- mindet = inf;
- for j = 1 : 290
- for i = 1 : 280
- needdet = det( CMAT{ i, j } );
- if needdet >= maxdet
- maxdet = needdet;
- maxmatrix = CMAT{ i, j };
- else mindet = needdet;
- end
- end
- end
- disp('初始矩阵的rank(A)阶子式的个数:')
- ChildMatrixOfNum = nchoosek( R, ofrank) * nchoosek( R, ofrank)
- disp('初始矩阵的不相同的rank(A)阶子式的个数:')
- UnlikeMatrixOfNum = UnlikeMatrixOfTotal
- disp('初始矩阵的rank(A)阶子式的行列式的最大值:')
- MaxOfDet = maxdet
- disp('初始矩阵的rank(A)阶子式的行列式的最小值:')
- MinOfDet = mindet
- disp('初始矩阵的rank(A)阶子式的行列式的最大值对应的子式:')
- MaxOfMatrix = maxmatrix
- celldisp(DMAT);
- end
复制代码 |
评分
-
1
查看全部评分
-
|