title: Solving a complex implicit equation on python
body: <p>I have this function:</p>
  
  <pre><code>atanh((y/10^3)-3)-((10^(3)*y^(3)-11*10^(6)*y**2 + 3.93*10^(10)*y - 4.47*10^13)/((y - 2 * 10^3)*(y -4 * 10^3)^3))=3.49875*10^(-4)*t-atanh(3) + 0.3489583 
  </code></pre>
  
  <p>(As you can see in the image).</p>
  
  <p><a href="https://i.stack.imgur.com/NV0HS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NV0HS.png" alt="Function"></a></p>
  
  <p>and I need it to return a y value (as a float), for a given time (t) value. I have to try the times t=0.1; t=2; t= 0,2.</p>
  
  <p>I tried the fsolve function but I get an error message. This is what I did:</p>
  
  <pre><code>from cmath import atanh
  from scipy.optimize import fsolve
  
  t=1
  def f(y,t):
      return atanh((y/10**3)-3)-((10**(3)*y**(3)-11*10**(6)*y**2 + 3.93*10**(10)*y - 4.47*10**13)/((y - 2 * 10**3)*(y -4 * 10**3)**3))-3.49875*10**(-4)*t+atanh(3) - 0.3489583
  
  fsolve(f(y,t),1.9)
  </code></pre>
  
  <p>For which I got this error:</p>
  
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-12-a340e1c537e4&gt; in &lt;module&gt;
        6     return atanh((y/10**3)-3)-((10**(3)*y**(3)-11*10**(6)*y**2 + 3.93*10**(10)*y - 4.47*10**13)/((y - 2 * 10**3)*(y -4 * 10**3)**3))-3.49875*10**(-4)*t+atanh(3) - 0.3489583
        7 
  ----&gt; 8 fsolve(f(y,t),1.9)
  
  &lt;ipython-input-12-a340e1c537e4&gt; in f(y, t)
        4 t=1
        5 def f(y,t):
  ----&gt; 6     return cmath.atanh((y/10**3)-3)-((10**(3)*y**(3)-11*10**(6)*y**2 + 3.93*10**(10)*y - 4.47*10**13)/((y - 2 * 10**3)*(y -4 * 10**3)**3))-3.49875*10**(-4)*t+cmath.atanh(3) - 0.3489583
        7 
        8 fsolve(f(y,t),1.9)
  
  ~\Anaconda3\lib\site-packages\sympy\core\expr.py in __complex__(self)
      283         result = self.evalf()
      284         re, im = result.as_real_imag()
  --&gt; 285         return complex(float(re), float(im))
      286 
      287     def __ge__(self, other):
  
  ~\Anaconda3\lib\site-packages\sympy\core\expr.py in __float__(self)
      278         if result.is_number and result.as_real_imag()[1]:
      279             raise TypeError("can't convert complex to float")
  --&gt; 280         raise TypeError("can't convert expression to float")
      281 
      282     def __complex__(self):
  
  TypeError: can't convert expression to float
  </code></pre>
  
  <p>What I was hoping to get on the output was y as a real number .
  I did search for other similar questions on this site but I still couldn't solve this problem . </p>