![]() |
How to make a double loop to evaluate this triple integral - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: How to make a double loop to evaluate this triple integral (/thread-42079.html) |
How to make a double loop to evaluate this triple integral - Safinazsalem - May-06-2024 I have a function f(t1,t2,t3, a,k) where I make a triple integral over t1,t2,t3 and make a loop on the value of the variable "k"-The integration limits of t1 and t2 are from 0 to a -The integration limits of t3 is from 0 to infinity The question is how to make a second loop over the variable a where it tends to zero Here is the code that I use: # %% 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.10061*10**-5;ti=-100*H;end=-H;step=H;a=0; f = lambda t1, t2,t3, k: t1 + t2 +k + a +t3 X = np.arange(0,50,0.1) g=float('inf') #plot(X,f(X)) def F(x): res = np.zeros_like(x) for i,val in enumerate(x): y,err = integrate.tplquad(f, 0, a,lambda x: 0, lambda x: a,lambda x,y: 0, lambda x,y: g,args=(val,)) res[i]=y/(math.exp(H*a)**2) return res plt.plot(X,F(X)) plt.title("P(k)") plt.show()As you glance that in this code I write f(t1,t2,t3,k) and let a=0 . But that makes the integral vanishesSo how to adjust this code and write f(t1,t2,t3,a,k) then run a second loop on "a" as a variable like "k" such that "a" tends to zero.Any help is appreciated! |