一种解决数值积分的快速方法

时间:2019-11-20 09:59:59

标签: python scipy

我正在尝试解决以下函数,该函数将其输出作为s的函数(Xi也是s的函数)。

enter image description here

我的PC需要花几个小时才能运行它。我想知道是否有更快的解决方案。

这是我的代码:

from scipy.integrate import quad
import numpy as np
from scipy import special
import scipy
import matplotlib.pyplot as plt
from mpmath import besselk, besseli, nsum, inf, exp
import random
import math
import pandas as pd
from itertools import product

pi = 5000
q = 2000
B = 1.2
vis = 1.2
k = 100
h = 50
phi = 0.25
Ct = 1e-5
C = 0.01 # welbore storage effect
rw = 0.25
skin = 30
re = 2000
zw = 10
b = 0.1 #Penetration ratio = hw/h
kzkr = 0.1
L = 500
omega = 0.001
lambda1 = 1e-7

tt = (np.logspace(0.0001, 10, num=10)).round(2)
print(tt)
lenght = len(tt)

cD = 0.8936*C/(h*phi*Ct*rw**2)
red = re/rw
zwD = zw/h
rDw = (rw/h)*(kzkr**0.5)
rwD = rw/L
zD = zwD + rw/h
LD = (L/h)*kzkr**0.5
hD = (1/LD)*(kzkr**-0.25)


# Bessel function I_n(u), K_n(u) on the real line for n=0,1
k0 = lambda u: besselk(0,u)
k1 = lambda u: besselk(1,u)
i0 = lambda u: besseli(0,u)
i1 = lambda u: besseli(1,u)


Lap_Func = lambda s: (1/(2*s)) * (quad(lambda z: k0((s*((0.732-z)**2))**0.5), -1, 1))[0] + (1/s)* (nsum(lambda n: (math.cos(n*math.pi*zwD)*math.cos(n*math.pi*(zwD+rwD)))*((quad(lambda z: k0(((s+(LD*n*math.pi)**2)*((0.732-z)**2))**0.5), -1, 1))[0]), [1, 20]))



stehfest = 10 # it should be an even number, usually between 10 and 14
k2 = int(stehfest/2)
InvLap = []
for ii in range(lenght):
    ViF = []
    for i in range(1, stehfest+1):
        M = []
        for k in range(int((i+1)/2), min(k2,i)+1):
            M.append(((k**(stehfest/2))*(math.factorial(2*k))) / (math.factorial((stehfest/2)-k) * math.factorial(k) * math.factorial(k-1) * math.factorial(i-k) * math.factorial((2*k)-i)))
        Vi = ((-1)**(stehfest/2 + i)) * ((np.array(M)).sum())
        ViF.append(Vi * Lap_Func((math.log(2))*i/tt[ii]))
        ft1 = ((np.array(ViF)).sum())
    ft = ((math.log(2))/tt[ii])*ft1
    InvLap.append(ft)
plt.loglog(tt, InvLap)
plt.show()

0 个答案:

没有答案