You're here: Home / Math /

Determinant of 3-by-3 matrices

The determinant of 3-by-3 matrices is defined as follows:


And no difference with the code:

<script type="text/javascript">

function det3x3(m) {
    d = m[0][0] * ( m[1][1] * m[2][2] - m[1][2] * m[2][1] ) -
        m[0][1] * ( m[1][0] * m[2][2] - m[1][2] * m[2][0] ) +
        m[0][2] * ( m[1][0] * m[2][1] - m[1][1] * m[2][0] );
    return(d);
}

/* always test */
var m = [ [-2, -1, -3],
          [ 5, -2,  3],
          [ 4, -3,  7] ];

alert( det3x3(m) ); /* will print: 54 */

</script>

Keywords: determinant, 3 by 3 matrix, javascript

Share:  del.icio.us logo Save to del.icio.us  digg logo Digg this!

comment.gifAdd your comment

(required, will not be published) (optional)