title: Estimate error using MATLAB (least squares)
body: <p>I have the equation ln(c)=-1/2k^2 * z^2, where y = ln(c), x = z^2 and a = -1/2k^2.</p>
  
  <p>I want to estimate the <code>a</code>, so:</p>
  
  <pre><code>a = polyfit(z.^2, log(abs(c)), 1)
  </code></pre>
  
  <p>Because I have the (initial) equation c = exp(-z^2/2k^2), from above I am  founding two values for <code>a</code> and now I want to estimate k (k1), so I do:</p>
  
  <pre><code>k1 = sqrt(-1/2*a(1))
  </code></pre>
  
  <p>Now, I want to predict c and error using values of k1 and z. So, I do:</p>
  
  <pre><code>c_predict = polyval(a,z)
  c1 = exp((-z.^2)/2*k1^2)
  error = c_predict - c1
  </code></pre>
  
  <p>Or just:</p>
  
  <pre><code>c1 = exp((-z.^2)./2*s1^2)
  error1 = c - c1
  </code></pre>
  
  <p>What is right?</p>
  
  <pre><code>error = c_predict - c1
  </code></pre>
  
  <p>or</p>
  
  <pre><code>error = c - c1
  </code></pre>
  
  <p>?</p>