title: How to create the design matrix for polynomial fitting when we have more than one independent variables?
body: <p>So, I know how to create this matrix when I have one independent variable - the first column is x^0, second is x^1 and so on.</p>
  
  <p>But now I have 5 independent variables in my source file. Where should I append these variables? To the design matrix as columns, starting with 1 again, or rows to the end? Any help appreciated, I feel lost.</p>
  
  <p>Preview from the data file:</p>
  
  <blockquote>
    <p>19.1711 17.6627 16.9633 16.6589 16.4254 0.075425 0.000735076<br>
    17.8339 16.0603 15.2756 14.9411 14.67 0.0473088 0.000123015<br>
    19.4924 17.7911 16.8446 16.3533 16.0243 0.075209 0.000393925<br>
    20.8318 19.0214 18.1391 17.6094 17.0731 0.131067 0.000252981<br>
    18.7056 16.6385 15.6452 15.2564 14.9338 0.131141 0.000217805<br></p>
  </blockquote>
  
  <p>The first five columns are the independent variables, the sixth is the y, and the last one is the error.</p>
  
  <p>According portion of my code:</p>
  
  <pre><code>int i, j, k;
  for(i=0;i&lt;(rows);i++)
  {
    for(j=0;j&lt;(pol+1);j++)
    {
      designm[(pol+1)*i+j] = 1;
      if(j==0)
        {
          continue;
        }
        else
          {
            for(k=0;k&lt;j;k++)
          {
              designm[(pol+1)*i+j] *= mat[cols*i+0];
          }
        }
      }
  }
  </code></pre>
  
  <p>What this does: I have the <code>mat</code> matrix, where I store everything I read from the source file. I have the <code>designm</code> where I store the design matrix. So far as you can see, I powered the first column of <code>mat</code> only, as I don't know where I should append the other four columns.</p>