public static final DenseMatrix64F get141Matrix ( int order ) { if ( order < 2 ) { throw new IllegalArgumentException ( "order has to be at least 2 for 1 4 1 matrix" ) ; } double [ ] data = new double [ order * order ] ; for ( int row = 0 ; row < order ; row ++ ) { for ( int col = 0 ; col < order ; col ++ ) { int index = row * order + col ; if ( row == col ) { data [ index ] = 4 ; } else { if ( Math . abs ( row - col ) == 1 ) { data [ index ] = 1 ; } else { data [ index ] = 0 ; } } } } return new DenseMatrix64F ( order , order , true , data ) ; }
Creates a 1 4 1 matrix eg . |4 1 0| |1 4 1| |0 1 4|