我一直在研究一种用于在并行处理中反转拉普拉斯变换的算法(即同时集成 s 空间中的多个拉普拉斯函数),但我知道并行处理不是问题,因为这种方法为解决问题而实施。但是问题仍然存在,基本上我的代码一遍又一遍地吐出这个:
Denominator too small. Exiting...
以及各种域错误。我指出了问题所在。基本上是这样的:
for u in np.linspace(0.000001, 100, 1000000):
u
当被传递给我想要集成的任何函数时,变为全零。不确定它是否是集成功能:
x_1[num] = x * (-1) ** k * quad(f_p(num), -math.pi / 2, math.pi / 2, args=(u,))[0]
或拉普拉斯函数f_p
本身,但我已经尝试了所有方法,我不能浪费更多时间旋转我的轮子。我会很感激我能得到的任何帮助。这是运行第一个拉普拉斯反演所需的代码:
import numpy as np
from scipy.integrate import quad
import math
import multiprocessing as mp
gamma = 10
num = 1
k = 1
n = 0
epsilon = 10 ** -16
max_err = 10 ** -10
max_count = 1000000
x_iter = np.arange(1, 7)
x_1 = np.arange(1, 7)
x_2 = np.arange(1, 7)
x_3 = np.arange(1, 7)
denom = np.arange(1, 7)
AX = np.arange(1, 7)
a = gamma
def f_p1(omega, u):
b = (omega + k * math.pi) / u
f1 = a * (1 / (a ** 2 + (b + 1) ** 2) + 1 / (a ** 2 + (b - 1) ** 2))
return f1 * math.cos(omega)
def f_p(num):
if num == 1:
return f_p1
def f_0(u, num):
x = 2 * math.e ** (gamma * u) / (math.pi * u)
return x * quad(f_p(num), 0, math.pi / 2, args=(u,))[0]
def f_u(u, num):
k = 1
x = 2 * math.e ** (gamma * u) / (math.pi * u)
x_1[num] = x * (-1) ** k * quad(f_p(num), -math.pi / 2, math.pi / 2, args=(u,))[0]
AX[num] = f_0(u, num)
for j in range(max_count):
if j > 0:
x_1[num] = x_iter[num]
k += 1
x_2[num] = x * (-1) ** k * quad(f_p(num), -math.pi / 2, math.pi / 2, args=(u,))[0]
k += 1
x_3[num] = x * (-1) ** k * quad(f_p(num), -math.pi / 2, math.pi / 2, args=(u,))[0]
denom[num] = (x_3[num] - x_2[num]) - (x_2[num] - x_1[num])
if(abs(denom[num]) < epsilon):
print("Denominator too small. Exiting...\n")
break
AX[num] = x_3[num] - ((x_3[num] - x_2[num]) ** 2) / denom[num]
k += 1
if(abs(AX[num] - x_3[num]) < max_err):
print("Equation " + str(num) + "converges to " + str(AX[num]) + "\n")
break
x_iter[num] = AX[num]
np.zeros(x_1)
np.zeros(x_2)
np.zeros(x_3)
np.zeros(denom)
np.zeros(AX)
if __name__ == '__main__':
mp.set_start_method('spawn')
for u in np.linspace(0.000001, 100, max_count):
p1 = mp.Process(target=f_u, args=(u, 1))
p2 = mp.Process(target=f_u, args=(u, 2))
p3 = mp.Process(target=f_u, args=(u, 3))
p4 = mp.Process(target=f_u, args=(u, 4))
p5 = mp.Process(target=f_u, args=(u, 5))
p6 = mp.Process(target=f_u, args=(u, 6))
p1.start()
p2.start()
p3.start()
p4.start()
p5.start()
p6.start()
p1.join()
p2.join()
p3.join()
p4.join()
p5.join()
p6.join()
exit(0)