title: Changing coefficient values in root finding
body: <p>I have the following code below:</p>
  <pre><code>import numpy as np
  import scipy as sc
  from scipy import optimize
  
  
  def fun(cd, pd, cr,  p1, lambda1,prev,n2, inspIdx):
      n1 = prev + n2
      deltan1 = cd*pd*lambda1*(1-p1)*n1 - cr*(1-pd)*(1-p1)*lambda1*n1*np.exp(-lambda1*pd*n1)
      deltan2 = cd*pd*lambda1*(1-p1)*n2 - cr*(1-pd)*(1-p1)*lambda1*n2*np.exp(-lambda1*pd*n2)
      return p1**inspIdx * deltan1 + (1-p1**inspIdx) * deltan2
  </code></pre>
  <p><code>n2</code> is the variable I want to find the root of this nonlinear function. However, the values of other variables change at every iteration and they're inside a for loop in the main function.</p>
  <p>I checked SymPy but couldn't figure it out how to change coefficient values. How can I assign the coefficient values and find the root with respect to <code>n2</code>?</p>