資源簡介
對二進制矩陣用高斯消元法求逆。輸入二進制矩陣,輸出其逆。比http://blog.sina.com.cn/s/blog_4b425443010008l6.html中方法更可靠和快速
代碼片段和文件信息
function?[?out?]?=?inv_bin(?in?)
%INV_BIN?Summary?of?this?function?goes?here
%???Detailed?explanation?goes?here
%???計算二進制稀疏矩陣的逆
[mn]?=?size(in);
if(m~=n)
???fprintf(‘m~=n\n‘);
???return?;
end
E?=?eye(m);
%%
%做行變換,變成下三角陣
for?i?=?1:m
????noneZerosIndex?=?find(in(:i));??%i到end行,第i列非零元
????noneZerosIndex?=?noneZerosIndex(find(noneZerosIndex>=i));
????if(length(noneZerosIndex)==0)??%該行為0
????????randIndex?=?randi([i+1m]1);
????????%列交換
????????temp?=?in(:i);
????????in(:i)?=?in(:randIndex);
????????in(:randIndex)?=?temp;
????????%E交換
????????temp?=?E(:i);
????????E(:i)?=?E(:randIndex);
?????
- 上一篇:純js和html可編輯的table表格
- 下一篇:Qt寫的實用鬧鐘,可以自己選擇音樂
評論
共有 條評論