title: Fastest way to do this double summation?
body: <p>What is the fastest way to do this summation<img src="https://i.stack.imgur.com/7jVLy.png" alt="enter image description here"> in R?</p>
  
  <p>This is what I have so far</p>
  
  <pre><code>ans = 0
  for (i in 1:dimx[1]){
    for (j in 1:dimx[2]){
      ans = ans + ((x[i,j] - parameters$mu)^2)/(parameters$omega_2[i]*parameters$sigma_2[j])
    }
  }
  </code></pre>
  
  <p>where <code>omega_2</code>, and <code>sigma_2</code> are omega^2 and sigma^2 respectively.</p>