title: Cost Function, Linear Regression, trying to avoid hard coding theta. Octave.
body: <p>I'm in the second week of Professor Andrew Ng's Machine Learning course through Coursera. We're working on linear regression and right now I'm dealing with coding the cost function.</p>
  
  <p>The code I've written solves the problem correctly but does not pass the submission process and fails the unit test because I have hard coded the values of theta and not allowed for more than two values for theta.</p>
  
  <p>Here's the code I've got so far</p>
  
  <pre><code>function J = computeCost(X, y, theta)
  
  m = length(y);
  J = 0;
  
  for i = 1:m,
      h = theta(1) + theta(2) * X(i)
      a = h - y(i);
      b = a^2;
      J = J + b;
      end;
  J = J * (1 / (2 * m));
  
  end
  </code></pre>
  
  <p>the unit test is </p>
  
  <pre><code>computeCost( [1 2 3; 1 3 4; 1 4 5; 1 5 6], [7;6;5;4], [0.1;0.2;0.3])
  </code></pre>
  
  <p>and should produce ans =  7.0175</p>
  
  <p>So I need to add another for loop to iterate over theta, therefore allowing for any number of values for theta, but I'll be damned if I can wrap my head around how/where.</p>
  
  <p>Can anyone suggest a way I can allow for any number of values for theta within this function?</p>
  
  <p>If you need more information to understand what I'm trying to ask, I will try my best to provide it.</p>