Javascript로 구성한 Gauss Jordan Elimination 역행렬 계산 알고리즘 // // Gauss Jordan Elimination // // 0. set unit matrix minv = []; for( r = 0; r < mat.length; r++){ minv[r] = []; for( c = 0; c < mat[r].length; c++){ minv[r][c] = 0; } minv[r][r] = 1; } // 1. calc inv mat // Start solving. for( r = 0; r < mat.length ; r++){ // by row // Zero out all entries in column r after this row. // See if this row has ..
직접 수식을 이용하여 역행렬을 계산하는 알고리즘. 행렬크기가 2X2이거나 3X3일때는 다음을 이용하여 계산하면 빠르게 구할 수 있다. 소스코드는 Javascript를 이용한 것이므로, 다른 프로그램을 이용할 경우는 해당 프로그램의 문법에 맞춰 수정해야한다. if( mat.length == 2 ){ det = mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1]; if( det == 0 ){ alert( "matrix is singular!"); } else { minv = []; minv.push( [ mat[1][1] / det, -1*mat[0][1] / det ] ); minv.push( [ -1* mat[1][0] / det, mat[0][0] /det ] ..