How to fix the error probability plot in Python for MIM and PNS attacks?

In summary, the conversation discusses the issue of converting equations into Python code and plotting a graph according to the equations. The equations of error probability for MIM attack and PNS attack are given, along with the conditions for satisfying the region. The conversation also includes a specific question about inserting one equation into another and a code for plotting the graph. The expert provides a code correction and the graph is successfully plotted, but there is still an issue with the error probability not being plotted correctly at N=0.
  • #1
Nur Ziadah
35
3
I have several equations and need to convert it into Python. The problem is that I tried to plot a graph according to the equation. However, the graph that I get is not the same as the original one.

In the paper, the equation of error probability for MIM attack is given by:

First Image
jlPMh.png

Second Image
h99h4.png

The equation to calculate the error probability of PNS attack is given by:
7CsYR.png

Where the region condition satisfied:
0Bxa3.png

The error probability of PNS attack should be plotted like this:
1IwAa.png

My question: How to insert equation 8.1 into equation 8.5?

This is my python code according to equation 8.5:

Python:
import matplotlib.pyplot as plt
import math
import numpy as np
from scipy.special import iv,modstruvex=[0, 5, 10, 15, 20]
t= 0.9
x = np.array(x)
y = (np.exp(x*t/2)*(iv(0, x*t/2) - modstruve(0,x*t/2))-1)/(np.exp(x*t/2-1))                                           

plt.plot(x, y, label='Normal')
plt.xlabel('Mean photon number N')
plt.ylabel('Error probabiity')
plt.scatter(x,y)
plt.title('N/2')
plt.ylim([0, 0.5])
plt.legend()
plt.show()

Please help me regarding this matter.

Thank you.
 

Attachments

  • jlPMh.png
    jlPMh.png
    3.3 KB · Views: 1,065
  • h99h4.png
    h99h4.png
    9.7 KB · Views: 1,086
  • 7CsYR.png
    7CsYR.png
    3.9 KB · Views: 1,052
  • 0Bxa3.png
    0Bxa3.png
    1.5 KB · Views: 968
  • 1IwAa.png
    1IwAa.png
    18.6 KB · Views: 1,034
Technology news on Phys.org
  • #2
When x=0 then N=0 hence the denominator is zero and so you are dividing zero according to the equation.

In your code, you misplaced the last paren. it should look like this:

Python:
y = (   np.exp(x*t/2) * (iv(0,x*t/2) - modstruve(0,x*t/2)) - 1   )  /  (np.exp(x*t/2) - 1)

This code now gives a runtime divide error at zero but the curve looks more like what you want.
 
  • #3
Thank you so much. Finally I did plot the graph.
 
  • #5

1. How do I convert an equation to Python?

To convert an equation to Python, you will need to use the correct syntax and operators for the equation you are trying to convert. This will involve breaking down the equation into smaller parts and using appropriate functions and mathematical operators to represent it in Python.

2. What are the important things to consider when converting an equation to Python?

When converting an equation to Python, you should consider the order of operations, data types, and any necessary libraries or modules that you may need to import. You should also be aware of any potential errors or bugs that may arise during the conversion process.

3. Are there any resources or tools that can help with converting equations to Python?

Yes, there are several resources and tools that can assist with converting equations to Python. These include online converters, libraries specifically designed for mathematical equations, and tutorials or guides on how to convert equations to Python.

4. Can I use variables in my converted equations in Python?

Yes, you can use variables in your converted equations in Python. Variables allow you to store and manipulate values within your code, making it easier to work with and modify equations as needed.

5. Is it possible to convert any type of equation to Python?

In most cases, yes, it is possible to convert any type of equation to Python. However, some complex or specialized equations may require advanced programming skills or specialized libraries to convert accurately.

Similar threads

  • Programming and Computer Science
Replies
21
Views
4K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
2
Views
868
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
856
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
Back
Top