数值积分方法'四元'导数误差

时间:2018-01-26 12:25:17

标签: python-3.x optimization scipy numerical-integration quad

我在下面定义了一系列函数,并插入了结束函数fA进行数值积分。集成与一个变量有关,因此其他参数作为数字传递,以便集成方法(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是一组初始猜测。谢谢!

0 个答案:

没有答案