title: Minimizing a function using python for data fitting
body: <p>I have a function as the following</p>
  
  <pre><code>q = 1 / sqrt( ((1+z)**2 * (1+0.01*o_m*z) - z*(2+z)*(1-o_m)) )
  h = 5 * log10( (1+z)*q ) + 43.1601
  </code></pre>
  
  <p>I have experimental answers of above equation and once I must to put some data into above function and solve equation below</p>
  
  <pre><code>chi=(q_exp-q_theo)**2/err**2  # this function is a sigma, sigma chi from z=0 to z=1.4 (in the data file)
  </code></pre>
  
  <p><code>z</code>, <code>err</code> and <code>q_exp</code> are in the data file(2.txt). Now I have to choose a range for <code>o_m</code> <code>(0.2 to 0.4)</code> and find in what <code>o_m</code>, the <code>chi</code> function will be minimized.</p>
  
  <p>my code is:</p>
  
  <pre><code>from math import *
  from scipy.integrate import quad
  
  min = None
  l = None
  a = None
  b = None
  c = 0
  
  
  def ant(z,om,od):
      return 1/sqrt( (1+z)**2 * (1+0.01*o_m*z) - z*(2+z)*o_d )
  
  
  for o_m in range(20,40,1):
      o_d=1-0.01*o_m
      with open('2.txt') as fp:
          for line in fp:
              n = list( map(float, line.split()) )
              q = quad(ant,n[0],n[1],args=(o_m,o_d))[0]
              h = 5.0 * log10( (1+n[1])*q ) + 43.1601
              chi = (n[2]-h)**2 / n[3]**2
              c = c + chi
          if min is None or min&gt;c:
              min = c
              l = o_m                            
          print('chi=',q,'o_m=',0.01*l)
  </code></pre>
  
  <p><code>n[1]</code>,<code>n[2]</code>,<code>n[3]</code>,<code>n[4]</code> are <code>z1</code>, <code>z2</code>, <code>q_exp</code> and <code>err</code>, respectively in the data file. and <code>z1</code> and <code>z2</code> are the integration range.
  I need your help and I appreciate your time and your attention.
  Please do not rate a negative value. I need your answers.</p>