public static double [ ] [ ] diag ( double [ ] vector ) { // Note: According to the Java Language spec, an array is initialized with the default value, here 0. double [ ] [ ] diagonalMatrix = new double [ vector . length ] [ vector . length ] ; for ( int index = 0 ; index < vector . length ; index ++ ) { diagonalMatrix [ index ] [ index ] = vector [ index ] ; } return diagonalMatrix ; }
Generates a diagonal matrix with the input vector on its diagonal