title: Matlab Matrix inner dimension must agree
body: <p>I have a simple quadratic form function. </p>
  
  <pre><code>function [y, grady] = quadobj(x)
  global Q
  y = x*Q*x';
  if nargout &gt; 1
      grady = 2*Q*x;
  end
  </code></pre>
  
  <p>When I simply calculate the quadratic form on the command line, it works.</p>
  
  <pre><code>&gt;&gt; [1 1 1]*Q*[1 1 1]'
  
  ans =
  
     -2.5977
  
  
  &gt;&gt; Q
  
  Q =
  
     -1.0000   -0.0731    0.3043
     -0.0731   -1.0000   -0.0300
      0.3043   -0.0300   -1.0000
  </code></pre>
  
  <p>But when I try to evaluate the function, I get an error</p>
  
  <pre><code>&gt;&gt; quadobj([1 1 1])
  Error using  * 
  Inner matrix dimensions must agree.
  
  Error in quadobj (line 3)
  y = x*Q*x';
  
  3   y = x*Q*x';
  </code></pre>
  
  <p>Why is this behavios occuring? It seems to me that the dimensions line up in the way I have written line three of the quadratic form function. Please help!</p>