title: Evaluate sum of integral numerically with Matlab using for loops
body: <p>I'm trying to evaluate the following type of problem with Matlab. </p>
  
  <p><img src="https://i.stack.imgur.com/3tOkW.png" alt="enter image description here"></p>
  
  <p>where the summation is taken over <code>wn</code> which is a vector, and the variable of integration is <code>wPrime</code>. <code>w</code>, <code>wn</code> and <code>Ri</code> are given vectors.</p>
  
  <p>What I've tried is the following: using two <code>for</code>-loops.</p>
  
  <pre><code>integral = zeros(size(wn));
  sumF = zeros(size(w));
  
  for j = 1:length(w);
      for k = 1:length(wn);
          integral(k) = trapz(wPrime,1./(w(j)-1i*wn(k)-wPrime));
      end
      sumF(j) = sum(integral.*wn./sqrt(Ri));
  end
  </code></pre>
  
  <p>but I've understood that for loops are very slow in Matlab, so I´m wondering if there is a better approach to this problem?</p>