title: Fitting Coefficients to Data and Function using Python
body: <p>I have to calculate the coefficients (c1-c9) of the function below, while both temperatures(to,tc) and the solution (y) is given through measured data at different points. I tried to solve it with numpy.linalg.solv but it raises a Singular Matrix error, which I am not sure how to avoid. </p>
  
  <pre><code> c[0] + c[[0]]*to[0] + c[[1]]*tc[0] + c[3]*to[0]^2 + c[4]*to[0]*tc[0] + c[5]*tc[0]^2 + c[6]*to[0]^3 + c[7]*tc[0]*to[0]^2 + c[8]*to[0]*tc[0]^2 + c[9]*tc[0]^3 = y[0]
  </code></pre>
  
  <p>Could someone give me a clue or a solution to how this problem can be solved with Python? This is my code so far</p>
  
  <pre><code>import numpy as np
  
  to1 = 10
  tc1 = 30
  y1  = 148450
  to2 = 5
  tc2 = 30
  y2  = 124955
  to3 = 0
  tc3 = 30
  y3  = 104596
  to4 = -5
  tc4 = 30
  y4  = 86964
  to5 = -10
  tc5 = 30
  y5  = 71704
  
  a = np.array([[1,to1,tc1, to1**2, to1*tc1], [1,to2,tc2,to2**2, to2*tc2],[1,to3,tc3,to3**2, to3*tc3],[1,to4,tc4,to4**2, to4*tc4],[1,to5,tc5,to5**2, to5*tc5]])
  b = np.array([y1,y2,y3,y4,y5])
  x = np.linalg.solve(a, b)
  print x
  </code></pre>