我正在尝试求解以下带有未知数 theta1、theta2、theta3 的积分方程组:
其中Phi和phi分别是使用scipy的fsolve和integrate得到的标准正态分布的cdf和pdf。这是我的代码:
import numpy as np
import math
import scipy.integrate as integrate
from scipy import integrate
from scipy.stats import norm
from scipy.optimize import fsolve
def function(xi, thetai, thetaj, thetak):
prod = 1
for t in theta:
prod = prod * (1 - norm.cdf(xi - t))
return prod * norm.pdf(xi - thetai)
def pi_i(thetai, thetaj, thetak):
return integrate.quad(function, -np.inf, np.inf)[0]
def equations(p):
t1, t2, t3 = p
return (pi_i(t1,t2,t3) - 0.5, pi_i(t2,t1,t3) - 0.3, pi_i(t3,t1,t2) - 0.2)
t1, t2, t3 = fsolve(equations, (1, 1, 1))
print(equations((t1, t2, t3)))
但是,当我运行代码时,会弹出以下错误: TypeError: function() Missing 3 requiredpositional argument: 'thetai', 'thetaj', and 'thetak'
那是因为在使用
function
param调用
integrate.quad
时需要包含函数
args
的参数
def pi_i(thetai, thetaj, thetak):
return integrate.quad(function, -np.inf, np.inf, args=(thetai, thetaj, thetak))[0]