I am trying to find the inverse of the following function using Newton Raphson Method: (This is the function) by transforming it into this. Here, k is a constant, and we know the value of y hence it also becomes a constant and we want to find the value of x.
I tried to write a python code for the same, with around 20000 iterations but it is not converging to the correct value. Can someone give me any hint where am I going wrong. The values of y and k are 0.64 and 0.583 and the first guess for x is 0.4. The expected value of x is 0.651 but even after number of iterations, I am getting -7.88. This is the first time I am working on such a problem.
Here is the code: (func_ is the differentiation of func)
import math
def NTUCalculator(x,y,k):
func = (x/(1-math.exp(-x))) + ((k*x)/(1-math.exp(-k*x))) - 1 - 1/y
func_ = (1-math.exp(-x)) - (x*math.exp(-x)) + (k*(1-math.exp(-k*x))) - (k*k*x*math.exp(-k*x))
return x - (func/func_)
NTU = 0.4
for i in range(20000):
NTU = NTUCalculator(NTU,0.64,0.583)
NTU

If the equation is $$\frac 1y={\frac{x}{1-e^x}+\frac{k x}{1-e^{-k x}}-1}$$ with $y=0.64$ and $k=0.583$, the solution is $x=4.10048$
Using Newton with $x_0=0$, the iterates are $$\left( \begin{array}{cc} n & x_n \\ 0 & 0.00000 \\ 1 & 3.23752 \\ 2 & 4.08909 \\ 3 & 4.10047 \\ 4 & 4.10048 \end{array} \right)$$
Even if you work with a constant derivative equal to $0.7915$ at $x=0$, you will converge to the same result after $15$ iterations.