title: Cannot cast array data from dtype('complex128') to dtype('float64') according to the rule 'safe'
body: <p>I am trying to solve an optimization problem as shown below. But every time I get an error <code>Cannot cast array data from dtype('complex128') to dtype('float64') according to the rule 'safe'</code>. 
  Can anyone help me to see what is wrong here in the code? </p>
  
  <pre><code>def func(vec):
  
      linspec = -(kx**2)+((1.-nu)*(kx**4))
      lin = linspec*np.fft.fft(vec)
      nlin = np.zeros_like(lin)
      nlinre = vec*vec
      nlinspec = np.fft.fft(nlinre)
      nlin = (0.5*1j*kx*nlinspec)
      sol = lin+nlin
      rhs = np.zeros_like(sol, dtype='complex')
      sol -= rhs
      sol = np.fft.ifft(sol).real
  
      return sol
  
  def kssol(u0):
  
      u1 = np.ones((2*Mx,), dtype='complex')
      #u1 = 100.*u0
      u = scipy.optimize.fsolve(func, u1)
  
      return u 
  </code></pre>