title: Sum of squared differences
body: <p>I'm trying to write a function <code>SSD</code> that takes two <strong>m</strong> <em>x</em> <strong>1</strong> vectors and calculates the sum of squared differences.</p>
  
  <p>I'm testing my SSD function with the vectors:</p>
  
  <pre><code>a = [0.5, -0.2, 1.7]';
  b = [0.2, 0.9, 0.45]';
  </code></pre>
  
  <p>and I'm expecting the answer <code>2.862500</code>, but the result I get is <code>0.947500</code></p>
  
  <p>My function is as follows:</p>
  
  <pre><code>function [ z ] = SSD( a, b )
  
          z = sum( a(:,1) - b(:,1).^ 2 );
  end
  </code></pre>
  
  <p>Am I right in thinking that <code>Z = sum( (Ai - Bi).^ 2 )</code> is the correct way to calculate the sum of squared differences? If so, why is my function not working correctly?</p>