public static double[][] diagonal(final double[] v1) {
    final int dim = v1.length;
    final double[][] result = new double[dim][dim];
    for(int i = 0; i < dim; i++) {
      result[i][i] = v1[i];
    }
    return result;
  }
public static double [ ] [ ] diagonal ( final double [ ] v1 ) { final int dim = v1 . length ; final double [ ] [ ] result = new double [ dim ] [ dim ] ; for ( int i = 0 ; i < dim ; i ++ ) { result [ i ] [ i ] = v1 [ i ] ; } return result ; }
Returns a quadratic matrix consisting of zeros and of the given values on
the diagonal.

@param v1 the values on the diagonal
@return the resulting matrix