How to combine integration equation in Python?

In summary, we use the equation of log-normal distribution and R(eta) in Python to calculate R^Rate-wise by integrating R(eta) over all possible eta from 0 to 1 using a probability distribution (PDTC) which is a log-normal distribution. This can be done using the scipy.integrate library in Python.
  • #1
Nur Ziadah
35
3
TL;DR Summary
I'm calculating key rate (R^Rate-wise) by integrating R(eta) over all possible eta from 0 to 1, with a probability distribution (PDTC) which is a log-normal distribution using Python language.
I'm calculating key rate (R^Rate-wise) by integrating R(eta) over all possible eta from 0 to 1, with a probability distribution (PDTC) which is a log-normal distribution.

The equation of log-normal distribution:
243810


The equation of R(eta):
243811


Therefore, R^Rate-wise = Integrate_0^1(R(eta)*P(eta)*d eta):
243812


This is Python code of log-normal distribution:
Python:
x=np.linspace(0,1,1000)
sigma0=[0.9]
color=['green']
for i in range(len(sigma0)):
    sigma=sigma0[i]
    y=1/(x*sigma*np.sqrt(2*np.pi))*np.exp(-(np.log(x/0.3)+(1/2*sigma*sigma))**2/(2*sigma*sigma))
    plt.plot(x,y,color[i])
plt.title('Lognormal distribution')
plt.xlabel('x')
plt.ylabel('lognormal density distribution')
#plt.xlim((0,0.002))
plt.ylim((0,5))
plt.show()

This is Python code of R(eta):
Python:
n1=np.arange(10, 55, 1)
n=10**(-n1/10)Y0=1*(10**-5)
nd=0.25
ed=0.03
nsys=nd*n
QBER=((1/2*Y0)+(ed*nsys))/(Y0+nsys)
H2=-QBER*np.log2(QBER)-(1-QBER)*np.log2(1-QBER)
Rsp=np.log10((Y0+nsys)*(1-(2*H2)))
print (Rsp)

plt.plot(n1,Rsp)
plt.xlabel('Loss (dB)')
plt.ylabel('log10(Rate)')
plt.show()

My question is how to integrate R(eta) over possible eta from 0 to 1? The output should be in the following figure (R^Rate-wise):

243813


The referred article can be find in this link: https://arxiv.org/pdf/1712.08949.pdf

Thank you so much.
 
Technology news on Phys.org
  • #2
I usually use the https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html to do numerical integration in Python. You will need to define a function which defines the integrand.
 

1. How do I import the necessary packages for integration in Python?

To import the necessary packages for integration in Python, you can use the following code:

from scipy.integrate import quad, simps, trapz

2. How do I define the function to be integrated?

You can define the function to be integrated in Python using the def keyword followed by the function name and its parameters. For example:

def f(x):

    return x**2

3. What is the syntax for performing integration in Python?

The syntax for performing integration in Python using the scipy.integrate package is as follows:

integrate.quad(func, a, b)

where func is the function to be integrated, and a and b are the lower and upper limits of integration, respectively.

4. How do I handle multiple variables in the integration function?

If your integration function has multiple variables, you can use the args keyword in the integrate.quad function to pass in a tuple of values for those variables. For example:

integrate.quad(func, a, b, args=(c, d))

This will integrate the function func with the variables x, y, and z set to c and d.

5. How do I check the accuracy of the integration in Python?

You can check the accuracy of the integration in Python by using the epsabs and epsrel arguments in the integrate.quad function. These arguments allow you to specify the absolute and relative tolerances for the integration. For example:

integrate.quad(func, a, b, epsabs=1.5e-8, epsrel=1.5e-8)

This will ensure that the integration is accurate up to 1.5e-8 in both absolute and relative error.

Similar threads

Replies
2
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
21
Views
4K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
2
Views
897
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
Back
Top