title: How to calculate sample and population variances in Matlab?
body: <p>I have a vector <code>a</code></p>
  
  <pre><code>a = [86 100 41 93 75 61 76 92 88 97]
  </code></pre>
  
  <p>And I want to calculate the <code>std</code> and <code>mean</code> by 
  myself:</p>
  
  <pre><code>&gt;&gt; mean(a)
  
  ans =
  
     80.9000
  
  &gt;&gt; std(a)^2
  
  ans =
  
    335.2111
  </code></pre>
  
  <p>But when I do it like that I get wrong variance:</p>
  
  <pre><code>&gt;&gt; avg = mean(a)
  
  avg =
  
     80.9000
  
  &gt;&gt; var = sum(a.^2)/length(a) - avg^2
  
  var =
  
    301.6900
  </code></pre>
  
  <p>What do I miss here ?</p>
  
  <p>why <code>sum(a.^2)/length(a) - avg^2 != std(a)^2</code> ?</p>