I want to perform some operations on a matrix depending on some condition. The matrix is:
mat1={{0.2,a1,b1,c1},{0.8,a2,b2,c2},{0.3,a3,b3,c3}}
- when the element in the first column is less than 0.5: nothing should happen to that specific row;
- when the element in the first column is larger than 0.5: I want to swap the second and the third element and define the fourth as their ratio;
For the above matrix, this operation should return:
mat2={{0.2,a1,b1,c1},{0.8,b2,a2,a2/b2},{0.3,a3,b3,c3}}
I would also like to keep track of the rows where it was necessary to make the swap operation.
what is the most efficient way to perform this operation in Mathematica?