python - 将方程式转换为 Python

标签 python matplotlib scipy equation

我有几个方程式,需要将其转换为 Python。问题是我试图根据方程绘制图表。但是,我得到的图表与原始图表不一样。

在论文中,MIM攻击的错误概率方程为:

第一张图片

Screen Shot

第二张图片

Screen Shot

计算 PNS 攻击错误概率的公式为:

Screen Shot

区域条件满足的地方:

Screen Shot

PNS 攻击的错误概率应该是这样绘制的:

screen Shot

我的问题:如何将等式 8.1 代入等式 8.5?

根据等式 8.5,这是我的 python 代码:

import matplotlib.pyplot as plt
import math
import numpy as np
from scipy.special import iv,modstruve


x=[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()

请帮我解决这个问题。

谢谢。

最佳答案

我更新了您的代码,使用图中给出的公式计算 N1 和 N2 的 y。这给了我 y1 和 y2,我认为它们是绘制函数 f(y1,y2) 的组成部分。但是,如果没有论文的其余部分,我无法弄清楚您提供的图像上到底画了什么。

以下代码生成与 f 非常相似的图像:y1,y2 -> y1+y2:

import matplotlib.pyplot as plt
import numpy as np
from scipy.special import iv, modstruve

x = range(0, 20, 1)
# t= 0.1
for t, color in zip([0.9, 0.1, 0.5], ['b', 'g', 'r']):
    x1 = (1 - t) * np.array(x)
    y1 = (np.exp(x1 / 2) * (iv(0, x1 / 2) - modstruve(0, x1 / 2)) - 1) / (np.exp(x1) - 1)
    x2 = (1 - t) * t * np.array(x)
    y2 = (np.exp(x2 / 2) * (iv(0, x2 / 2) - modstruve(0, x2 / 2)) - 1) / (np.exp(x2) - 1)

    y = y1 + y2

    plt.plot(x, y, label=t, color=color)
    plt.scatter(x, y, color=color)

# N1 = N2
x1 = np.array(x) / 2
y1 = (np.exp(x1 / 2) * (iv(0, x1 / 2) - modstruve(0, x1 / 2)) - 1) / (np.exp(x1) - 1)
x2 = np.array(x) / 2
y2 = (np.exp(x2 / 2) * (iv(0, x2 / 2) - modstruve(0, x2 / 2)) - 1) / (np.exp(x2) - 1)
y = y1 + y2
plt.plot(x, y, label="N1=N2=N/2", color='k')
plt.scatter(x, y, color='k')

plt.xlabel('Mean photon number N')
plt.ylabel('Error probabiity')
plt.title('N/2')
plt.ylim([0, 0.35])
plt.legend()
plt.show()

enter image description here

关于python - 将方程式转换为 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53843713/

相关文章:

python - matplotlib 圆,动画,如何去除动画中的旧圆

python - 在 matplotlib 中使用 ax.annotate 返回箭头和文本

python - DataFrame 中的几何平均值

python - Numpy->Cython 转换 : Compile error:Cannot convert 'npy_intp *' to Python object

python - 使用 COBYLA 方法进行盆地跳跃似乎可以忽略约束

python - 使用 import random,使用 random.choice 抛出 AttributeError

python - 增加Python中cProfiler的深度来报告更多的功能?

python - 如何从文本文件中删除花括号?

Python:如何在给定索引列表的字符串中替换子字符串

python - Pandas groupby 在保留多个聚合的组内进行排序,并使用构面将其可视化