title: fit straight lines with gnuplot
body: <p>i want to use gnuplot to get fit parameters of a first degree polynomial equation (F(x)=a*x+b) for many curvers. Some of the curves are represented exactly straight lines.</p>
  
  <p>For example if my data look like</p>
  
  <pre><code>1 1
  2 2
  3 3
  4 4
  </code></pre>
  
  <p>which can be represented with the f(x)=x (param a=0, b=0).</p>
  
  <p>But the following gnuplot code</p>
  
  <pre><code># regression line
  f(x) = a*x + b
  fit f(x) './test.dat' u 1:2  via a, b
  </code></pre>
  
  <p>fails to compute fit params giving the message below</p>
  
  <pre><code>Singular matrix in Invert_RtR
  </code></pre>
  
  <p>update: It seems that gnuplot does not "crash" if i define the number of iterations for fit function </p>
  
  <pre><code>FIT_MAXITER = 1
  # regression line
  f(x) = a*x + b
  fit f(x) './test.dat' u 1:2  via a, b
  </code></pre>
  
  <p>It should be a=1 and b=0. But gnuplot gives</p>
  
  <pre><code>Final set of parameters            Asymptotic Standard Error
  =======================            ==========================
  
  a               = 0.989067         +/- 0.004339     (0.4387%)
  b               = 0.0761393        +/- 0.02692      (35.36%)
  </code></pre>
  
  <p>How can i "force" gnuplot compute the correct values of a and b?</p>