added condition in matrix and vector form