May-20-2024, 09:43 AM
When I run the following triple integral in python, it gives me an error:
IntegrationWarning: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achievedHere is the code, it is to plot a triple integral
f(t1, t2, m, k)
against a variable k
. import numpy as np import scipy.special from scipy import integrate from scipy.special import kn import matplotlib.pyplot as plt import math import time, sys H = 4 ti = -H a = 0.1 f = lambda t1, t2, m, k: (k**3 * m**3) * (1/(H * t1)) * (1/(H * t2)) * (2/k)**2 X = np.arange(0, 50, 0.1) g = float('inf') def F(x): res = np.zeros_like(x) for i, val in enumerate(x): y, err = integrate.tplquad(f, ti, a, lambda x: ti, lambda x: a, lambda x, y: 0, lambda x, y: g, args=(val,)) res[i] = y return res plt.plot(X, F(X)) plt.title("P(k), H=2.5") plt.xlabel("k") plt.ylabel("P") plt.savefig('P(k).png') plt.show()How can I run the code without
IntegrationWarning
?