DPdl DPdl - 4 years ago 73
Python Question

Calculating value of x for which f(x) is given

This may be a simple question, but I can't wrap my head around it. Say,

nb = 100
tb = 25
ns = 90
ts = 15
A0 = 1
S_norm = 0.4


R = tb/ts
y_meas = (ns-nb/R)/A0
sigma_meas = np.sqrt(ns+(nb+1)/R**2)/A0
def likelihood(y):

def func_likelihood(x):
return np.exp(-0.5*(((x/A0)/S_norm)**2 + ((y-y_meas*A0/np.exp(x))/sigma_meas)**2))

return (scipy.integrate.quad(func_likelihood,-10,10))[0]


Is there an easy way to determine value of y such that likelihood(y) is 0.025?

Answer Source

Have you tried scipy.optimize.fsolve?

from scipy.optimize import fsolve


def func(y):
    return likelihood(y) - 0.025

print(fsolve(func, 0))

Result:

[-7.3920919]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download