fix bug in triangular_matrix