If is a symmetric matrix and is the lower triangular part of the matrix and is the upper triangular part of the matrix: where the diagonal function only finds the diagonal elements of . This is because of a few relations:
To save time and space on MATLAB (because the upper triangular matrix will take up much more space), take advantage of the relations:
Now, the MATLAB calculation is
A_times_x = A_LT*x+(x.'*A_LT).'+ diag(A_LT).*x;
This should only perform transposes on the smaller resultant matrices.