title: Solve nonlinear equation in python
body: <p>I am trying to find the fundamental TE mode of the dielectric waveguide. The way I try to solve it is to compute two function and try to find their intersection on graph. However, I am having trouble get the intersect point on the plot. 
  My code:</p>
  
  <pre><code>def LHS(w):
      theta = 2*np.pi*1.455*10*10**(-6)*np.cos(np.deg2rad(w))/(900*10**(-9))
      if(theta&gt;(np.pi/2) or theta &lt; 0):
          y1 = 0
      else:
          y1 = np.tan(theta)
      return y1
  
  def RHS(w):
      y = ((np.sin(np.deg2rad(w)))**2-(1.440/1.455)**2)**0.5/np.cos(np.deg2rad(w))
      return y
  
  x = np.linspace(80, 90, 500)
  
  LHS_vals = [LHS(v) for v in x]
  RHS_vals = [RHS(v) for v in x]
  
  
  # plot
  fig, ax = plt.subplots(1, 1, figsize=(6,3))
  ax.plot(x,LHS_vals)
  ax.plot(x,RHS_vals)
  ax.legend(['LHS','RHS'],loc='center left', bbox_to_anchor=(1, 0.5))
  
  plt.ylim(0,20)
  plt.xlabel('degree')
  plt.ylabel('magnitude')
  plt.show()
  </code></pre>
  
  <p>I got plot like this:
  <a href="https://i.stack.imgur.com/0qu5G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0qu5G.png" alt="graph"></a></p>
  
  <p>The intersect point is around 89 degree, however, I am having trouble to compute the exact value of x. I have tried fsolve, solve to find the solution but still in vain. It seems not able to print out solution if it is not the only solution. Is it possible to only find solution that x is in certain range? Could someone give me any suggestion here? Thanks! </p>
  
  <p>edit:
  the equation is like this (m=0):
  <a href="https://i.stack.imgur.com/GDJH9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GDJH9.png" alt="enter image description here"></a></p>
  
  <p>and I am trying to solve theta here by finding the intersection point</p>
  
  <p>edit:
  One of the way I tried is as this:</p>
  
  <pre><code>from scipy.optimize import fsolve
  def f(wy):
     w, y = wy
     z = np.array([y - LHS(w), y - RHS(w)])
     return z
  
  fsolve(f,[85, 90])
  </code></pre>
  
  <p>However it gives me the wrong answer.
  I also tried something like this:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  x = np.arange(85, 90, 0.1)
  f = LHS(x)
  g = RHS(x)
  
  plt.plot(x, f, '-')
  plt.plot(x, g, '-')
  
  idx = np.argwhere(np.diff(np.sign(f - g)) != 0).reshape(-1) + 0
  plt.plot(x[idx], f[idx], 'ro')
  print(x[idx])
  plt.show()
  </code></pre>
  
  <p>But it shows:
  ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()</p>