pythonscipy-optimizenumerical-computing

Numerical Solver in Python is not able to find a solution


I broke my problem down as follows. I am not able to solve the following equation with Python 3.9 in a meaningful way, instead it always stops with the initial_guess for small lambda_ < 1. Is there an alternative algorithm that can handle the error function better? Or can I force fsolve to search until a solution is found?

import numpy as np
from scipy.special import erfcinv, erfc
from scipy.optimize import root, fsolve

def Q(x):
    return 0.5*erfc(x/np.sqrt(2))

def Qinvers(x):
    return np.sqrt(2)*erfcinv(2*x)

def epseqn(epsilon2):
    lambda_ = 0.1
    return Q(lambda_*Qinvers(epsilon2))

eps1 = fsolve(epseqn, 1e-2)
print(eps1)

I tried root and fsolve to get a solution. Especially for the gaussian error function I do not find a solution that converges.


Solution

  • root and fsolve can be used to find the roots of a function defined by f(x)=0. Since your outer function, which is basically erfc(x), has no root (it only it approaches the x-axis asymptotically from positive values) the solvers are not able to find one. Real function arguments are assumed like you did.