0

I want to find a function's x value at y=0.

from pynverse import inversefunc
from math import pi,sqrt
R=20
C=5*10**-9
L=5*10**-4
Z= (lambda x: sqrt(R**2+(1/(2*pi*C*x)-2*pi*L*x)**2))
inversefunc(Z,y_values=0)

But I get following error code:

Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
inversefunc(Z,y_values=0)
File "C:\Python27\lib\site-packages\pynverse\inverse.py", line 113, in inversefunc
trend = np.sign(func(ref2, *args) - func(ref1, *args))
File "<pyshell#15>", line 1, in <lambda>
Z= (lambda x: sqrt(R**2+(1/(2*pi*C*x)-2*pi*L*x)**2))
ZeroDivisionError: float division by zero

Please help me why! Thank you.

ruohola
  • 21,987
  • 6
  • 62
  • 97

1 Answers1

0

You can inform that the answer is undefined when the divisor is 0, and you should use normal functions, not named lambdas in python.

from pynverse import inversefunc
from math import pi,sqrt


def Z(x):
    # Can define these globally if necessary.
    R = 20
    C = 5 * 10**-9
    L = 5 * 10**-4

    return sqrt(R**2 + (1/(2*pi*C*x) - 2*pi*L*x)**2))


try:
    inversefunc(Z, y_values=0)
except ZeroDivisionError:
    print("answer is undefined")
ruohola
  • 21,987
  • 6
  • 62
  • 97