# Speeding up a serie of matrix operations/tranformations

For a model I am developing I found an matrix operation alternative of a for loop strategy

``````	matrix[I1_dim[1], I1_dim[2]] lambda_mat_1 = to_matrix(lambda[idx_1], I1_dim[1], I1_dim[2]); // Bug prone

matrix[Q, ct_in_levels[1]] prop_mat_1 = vector_array_to_matrix(prop_1); //prop1 is a simplex

matrix[I1_dim[1] , Q] lambda_sum_1 = lambda_mat_1 * prop_mat_1';

matrix[I1_dim[1], I1_dim[2]] sigma_mat_1 = to_matrix(sigma[idx_1], I1_dim[1], I1_dim[2]);

matrix[I1_dim[1], Q] sigma_sum_1 =  square(lambda_sum_1) ./ (( square(lambda_mat_1) ./ sigma_mat_1 ) * square(prop_mat_1')) ;

``````

Although can reduce execution time of 50%, I would like to improve further (considering that I can parallelise the for loop with map_rect).

In this list of commands I have to do multiple conversion between vectors, matrices etcâ€¦

Is there anything I should avoid? That is computationally heavy by definition? (e.g., the creation of so many intermediate variables)

Thsnks.