0

我在下面定义了一系列函数,其中fA插入了 end 函数以进行数值积分。积分是针对一个变量的,因此其他参数作为数字传递,以便积分方法 ( quad) 可以继续

import numpy 
import math as m
import scipy
import sympy

#define constants                                                                                                                                                                    
gammaee = 5.55e-6
MJpsi = 3.096916
alphaem = 1/137
lambdasq = 0.09
Ca = 3
qOsq = 2


def qbarsq(qsq):
    return (qsq+MJpsi**2)/4


def xx(qbarsq, w):
    return 4*qbarsq/(4*qbarsq-MJpsi**2+w**2)

from sympy import *

x,NN,a,b,ktsq,qbarsq,w = symbols('x NN a b ktsq qbarsq w')


def xg(a,b,NN,ktsq,x):
    return NN*(x**(-a))*(ktsq**b)*exp(sqrt((16*Ca/9)*log(1/x)*log((log(ktsq/lambdasq))/(log(qOsq/lambdasq)))))


#prints symbolic derivative of xg                                                                                                                                                    
def func(NN,a,b,x,ktsq):
    return (-x*diff(log(xg(a,b,NN,ktsq,x)),x))
#print(func(NN,a,b,x,ktsq))                                                                                                                                                          



#prints symbolic expression for Rg                                                                                                                                                   
def Rg(NN,a,b,ktsq,x):
    return 2**(2*func(NN,a,b,x,ktsq)+3)/sqrt(m.pi)*gamma(func(NN,a,b,x,ktsq)+5/2)/gamma(func(NN,a,b,x,ktsq)+4)
#print(Rg(NN,a,b,ktsq,x))

#prints symbolic expression for Fktsq                                                                                                                                                
def FktsqDeriv(NN,a,b,x,ktsq):
    return diff(Rg(NN,a,b,ktsq,x)*xg(a,b,NN,ktsq,x),ktsq)
#print(FktsqDeriv(NN,a,b,x,ktsq))                                                                                                                                                   


def Fktsq1(qbarsq,ktsq,NN,a,b,w):
    return FktsqDeriv(NN,a,b,x,ktsq).subs(x,4*qbarsq/(4*qbarsq-MJpsi**2+w**2))
print(Fktsq1(qbarsq,ktsq,NN,a,b,w))

# symbolic expression for fA                                                                                                                                                         
def fA(qbarsq,ktsq,NN,a,b,w):
    return Fktsq1(qbarsq,ktsq,NN,a,b,w)*1/(qbarsq)*1/(qbarsq+ktsq)
#print(fA(qbarsq,ktsq,NN,a,b,w))

我现在想将最后一个功能集成ktsq如下,

import scipy.integrate.quadrature as sciquad
def integrated_f(NN,a,b,w,qbarsq):
    return sciquad(fA,1,(w**2-MJpsi**2)/4, args=(NN, a, b, w, qbarsq))

a=0.1
NN=0.5
b=-0.2
w=89
qbarsq=5
result = integrated_f(NN,a,b,w,qbarsq)
print(result)

问题是我试图通过为每个其他参数指定数值来从这个集成中得到一个数字。错误是

ValueError: Can't calculate 1st derivative wrt 989.426138911118.

我对此的唯一解释是该方法无法处理函数的复杂性(尽管我认为它在结构上相对简单),因为我没有定义更多的导数,当然也没有定义这个值。有简单的解决方案吗?实际上,我希望使用该函数integrated_f在优化问题中使用最佳拟合参数a,b,NN。会像

scipy.optimize.minimize(integrated_f, x0, method='Nelder-Mead', options={'max\ iter': 1000})x0对于初始猜测数组的多变量函数没问题。谢谢!

4

0 回答 0