title: Matlab: What's faster? Predefining helpful objects or not?
body: <p>I have to do calculations in matlab with very large matrices. I have already made sure to use matrix operations where possible etc. Now trying to fine-tune.
  So let A, B, C and D be matrices:</p>
  
  <pre><code>C=A*B;
  D=cos(C);
  </code></pre>
  
  <p>It seems trivial that the following would be faster (correct me if I'm wrong):</p>
  
  <pre><code>D=cos(A*B)
  </code></pre>
  
  <p>My question is if the same it is faster to do if there is more calls of the predefined object:</p>
  
  <pre><code>D=f1(A*B) + f2(A*B) + …;
  </code></pre>
  
  <p>instead of predefining C=A*B (which would save a lot of calculations I assume). I have a lot of this kind of expression so some general insight would be useful (at least to know on what kind of parameters i.e. matrix size it depends).</p>