title: Implementing a never ending matrix formula on python for curve fitting
body: <p>I'm trying to write a program that can solve the general regression formula:
  <a href="https://i.stack.imgur.com/j8LDY.png" rel="nofollow noreferrer">So I'm trying to implement this matrix equation</a>, is there anyway to do this such as to let the user decide how big it can be, without me making more and more if conditions (so just one piece of code that collapses to the matrix that the user wishes for)?
  Code:</p>
  
  <pre><code>    #Solving the general matrix for the coefficients
  if 3 == n:
      a = np.array([[np.sum(np.multiply(FL[1],FL[1])),np.sum(np.multiply(FL[1],FL[2]))],
                      [np.sum(np.multiply(FL[1],FL[2])),np.sum(np.multiply(FL[2],FL[2]))]])
      b = np.array([np.sum(np.multiply(FL[0],FL[1])),np.sum(np.multiply(FL[0],FL[2]))])
      x = np.linalg.solve(a, b)
  if 4 == n:
      a = np.array([[np.sum(np.multiply(FL[1],FL[1])),np.sum(np.multiply(FL[1],FL[2])),np.sum(np.multiply(FL[1],FL[3]))],
                      [np.sum(np.multiply(FL[1],FL[2])),np.sum(np.multiply(FL[2],FL[2])),np.sum(np.multiply(FL[2],FL[3]))],
                      [np.sum(np.multiply(FL[1],FL[3])),np.sum(np.multiply(FL[2],FL[3])),np.sum(np.multiply(FL[3],FL[3]))]])
      b = np.array([np.sum(np.multiply(FL[0],FL[1])),np.sum(np.multiply(FL[0],FL[2])),np.sum(np.multiply(FL[0],FL[3]))])
      x = np.linalg.solve(a, b)
  
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/j8LDY.png" rel="nofollow noreferrer">1</a> In this code Phi_0 corresponds to FL[i=1] and FL[0] corresponds to y.</p>