title: Understanding fminunc arguments and anonymous functions, function handlers
body: <p>Please bear with me. The question is at the end. I am trying to figure out the difference in how fminunc is called. </p>
  
  <p>This question stems from Andrew Ng's Week 3 material in his Coursera Machine Learning course. 
  I am bouncing off of this question. <a href="https://stackoverflow.com/questions/43961765/what-is-short-hand-in-matlab">Matlab: Meaning of @(t)(costFunction(t, X, y)) from Andrew Ng&#39;s Machine Learning class</a></p>
  
  <p>I am trying to understand the meaning of the argument</p>
  
  <pre><code>@(t) ( costFunction(t, X, y) )
  </code></pre>
  
  <p>User wolfie, showed it as being a shortened version. Could anyone explain why the expression itself has to be like that? In the video lecture, he ran the function like this </p>
  
  <pre><code>[optTheta, functionVal, exitFlag] = fminunc(@costFunction, initialTheta, options)
  </code></pre>
  
  <p>where <code>costFunction</code> inputs and outputs from the program file are given as:</p>
  
  <pre><code>function [jVal, gradient] = costFunction(theta)
  </code></pre>
  
  <p>The exercise provided code has this version of the function: 
  <code>costFunction(theta, X, y)</code>.</p>
  
  <p>Why wasn't fminunc called like in the second case without the anonymous function, that is why was it called as:</p>
  
  <p><code>[theta, cost] = fminunc(@(t)(costFunction(t, X, y)), initial_theta, options);</code></p>
  
  <p>instead of as:</p>
  
  <p><code>[theta, cost] = fminunc(@costFunction, initial_theta, options);</code> ?</p>