Instantly share code, notes, and snippets.

Created January 10, 2015 09:38
Show Gist options
• Save sasekazu/a406c51adca34a37f2cc to your computer and use it in GitHub Desktop.
jacobi法による対角化 jacobi diagonalization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 // jacobi法による実対称行列の対角化 // numeric.jsが必要 // 他の関数との依存性排除ver // size: 行列サイズ // intputA: 対角化される入力行列 ※対称行列でなければならない // 返り値 {DiagonalMatrix:A, OrthodonalMatrix:P}; // A(入力時) = P A(対角化後) P.transpose が成り立つ function jacobiDiagonalization(size, inputA, maxIteration, threshold) { var A=numeric.clone(inputA); // Pを単位行列で初期化 var P=new Array(size); for(var i=0; i

### sasekazu commented Jan 10, 2015

``````var maxiteration = 1000;
var size = 30;
var A=numeric.random([size, size]);
for(var i=1; i<size; ++i) {
for(var j=0; j<i; ++j) {
A[i][j]=A[j][i];
}
}
var result=jacobiDiagonalization(size, A, maxIteration, threshold);
var D = numeric.clone(result.DiagonalMatrix);
var P = numeric.clone(result.OrthodonalMatrix);
``````