Funktionenproblem
Verfasst: Mittwoch 27. März 2019, 17:38
Hallo liebe Leute,
ich bin ein waschechter Anfänger was Python angeht und auch in diesem Forum. Da ich es aber für mein Studium/ Arbeit brauche, habe ich mir gedacht das jetzt mal alles anzufangen.
Für meine Arbeit muss ich einen Grafen zeichnen der sich auch vielen anderen Funktionen zusammen setzt.
Wenn ich das Programm normal laufen lasse ohne zu plotten, gibt es kommt keine Fehlermeldung. Wenn ich es aber ploten möchte kommt: unsupported operand type(s) for /: 'function' and 'int'
Ich schreib euch mal meine Sachen hin:
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
n_p = 0.66 # preparation efficiency n_p:
T_p = 2 # preparation time T_p in mikrosekunden
n_c = 0.04*0.3 #photon-fiber coupling efficiency x wavelength conversion n_c
T_2 = 1 # dephasing time T_2 in s
c = 2,9979*(10**8)
L_att = 22 # attenuation length L_att in km
e_mA = 0.01 #misalignment error e_mA
n_d = 0.3 #detector efficiency
e_mB = 0.01 #misalignment error e_mB
p_d = 10**(-8) # dark count probability per detector
p_BSM = 1 # BSM success probability p_BSM
lambda_BSM = 0.97 # detector efficiency lambda_BSM
f = 1.16 # error correction inefficiency f
n_tot = n_p*n_c*n_d
epsilon_m = e_mA*(1-e_mB) + (1- e_mA)*e_mB
def teta(L):
return T_p + 2*L/c
def epsilon_dp(L):
return ((n_As * n_Bs * np.exp(-2*L/(c*T_2)))/(n_As + n_Bs - n_As * n_Bs))*(1/(1 - np.exp(-teta/T_2) * (1 - n_As)) + 1/(1 - np.exp(-teta/T_2) * (1 - n_Bs)))
def alpha(L):
return (n_As * (1 - p_d))/(1-(1-n_As)(1-p_d)**2)
def e_z(L):
return lambda_BSM * alpha**2 + 0.5 * (1 - lambda_BSM * alpha**2)
def e_x(L):
return lambda_BSM * alpha**2 *(epsilon_m*(1-epsilon_dp) + (1 - epsilon_m) * epsilon_dp) + 0.5 * (1- lambda_BSM * alpha**2)
def h(x):
return -x * np.log2(x) - (1-x)* np.log2(1-x)
def n_A(L):
return n_tot * np.exp(-L/L_att)
def n_As(L):
return 1 - (1 - n_A)*(1 - p_d)**2
def n_Bs(L):
return 1 - (1 - n_A)*(1 - p_d)**2
def Y(L):
return p_BSM * (1/n_As + 1/n_Bs - 1/(n_As + n_Bs - n_As*n_Bs))**(-1)
def R(L):
return Y/2 * (1 - h(e_x) - f*h(e_z))
l_werte = np.arange(0,70,0.1)
plt.plot(l_werte, R(l_werte))
plt.show()
Ich hoffe jemand kann mir sagen wo das Problem ist und bedanke mich für eure Hilfe
Viele Grüße
ich bin ein waschechter Anfänger was Python angeht und auch in diesem Forum. Da ich es aber für mein Studium/ Arbeit brauche, habe ich mir gedacht das jetzt mal alles anzufangen.
Für meine Arbeit muss ich einen Grafen zeichnen der sich auch vielen anderen Funktionen zusammen setzt.
Wenn ich das Programm normal laufen lasse ohne zu plotten, gibt es kommt keine Fehlermeldung. Wenn ich es aber ploten möchte kommt: unsupported operand type(s) for /: 'function' and 'int'
Ich schreib euch mal meine Sachen hin:
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
n_p = 0.66 # preparation efficiency n_p:
T_p = 2 # preparation time T_p in mikrosekunden
n_c = 0.04*0.3 #photon-fiber coupling efficiency x wavelength conversion n_c
T_2 = 1 # dephasing time T_2 in s
c = 2,9979*(10**8)
L_att = 22 # attenuation length L_att in km
e_mA = 0.01 #misalignment error e_mA
n_d = 0.3 #detector efficiency
e_mB = 0.01 #misalignment error e_mB
p_d = 10**(-8) # dark count probability per detector
p_BSM = 1 # BSM success probability p_BSM
lambda_BSM = 0.97 # detector efficiency lambda_BSM
f = 1.16 # error correction inefficiency f
n_tot = n_p*n_c*n_d
epsilon_m = e_mA*(1-e_mB) + (1- e_mA)*e_mB
def teta(L):
return T_p + 2*L/c
def epsilon_dp(L):
return ((n_As * n_Bs * np.exp(-2*L/(c*T_2)))/(n_As + n_Bs - n_As * n_Bs))*(1/(1 - np.exp(-teta/T_2) * (1 - n_As)) + 1/(1 - np.exp(-teta/T_2) * (1 - n_Bs)))
def alpha(L):
return (n_As * (1 - p_d))/(1-(1-n_As)(1-p_d)**2)
def e_z(L):
return lambda_BSM * alpha**2 + 0.5 * (1 - lambda_BSM * alpha**2)
def e_x(L):
return lambda_BSM * alpha**2 *(epsilon_m*(1-epsilon_dp) + (1 - epsilon_m) * epsilon_dp) + 0.5 * (1- lambda_BSM * alpha**2)
def h(x):
return -x * np.log2(x) - (1-x)* np.log2(1-x)
def n_A(L):
return n_tot * np.exp(-L/L_att)
def n_As(L):
return 1 - (1 - n_A)*(1 - p_d)**2
def n_Bs(L):
return 1 - (1 - n_A)*(1 - p_d)**2
def Y(L):
return p_BSM * (1/n_As + 1/n_Bs - 1/(n_As + n_Bs - n_As*n_Bs))**(-1)
def R(L):
return Y/2 * (1 - h(e_x) - f*h(e_z))
l_werte = np.arange(0,70,0.1)
plt.plot(l_werte, R(l_werte))
plt.show()
Ich hoffe jemand kann mir sagen wo das Problem ist und bedanke mich für eure Hilfe

Viele Grüße