-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfit_data.py
More file actions
72 lines (49 loc) · 1.49 KB
/
fit_data.py
File metadata and controls
72 lines (49 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
# used for uebung 7 Festkoerper 1 VL
k_b = 1.38e-23
G_2 = (2*np.pi*8/(0.4e-9))**2
M = 0.068/(6e23)
plt.xlabel("Temperature [K]")
plt.ylabel("Intensity")
# exponential fit function
def fit_function(T,b):
return 0.31*np.exp(-(k_b*G_2/(M*b**2)*T))
#linear fit function
def fit_lin(T, b, c):
return -(k_b*G_2/(M*b**2))*T + c
# Temperature
t = np.array([0, 100, 200, 300, 400, 500])
# Intensities
I = np.array([0.31, 0.22, 0.16,0.1,0.06,0.03])
# ln of I/I_0
I_ln = [np.log(i/0.31) for i in I]
b0 = np.array([20e12])
data = [(0,0.31),
(100,0.22),
(200,0.16),
(300,0.1),
(400,0.06),
(500,0.03)
]
# plot data points and linear intrapolation
plt.plot(t, I, label="data, linear intrapolated")
plt.plot(t, I, 'or', label="data, points")
# fit exponentialy
fitParams, fitCo = curve_fit(fit_function, t, I, b0)
# fit linear
linfit_Params , fitCO = curve_fit(fit_lin, t, I_ln)
# print the fitted parameters
print(fitParams)
print(linfit_Params)
# calculate first w by hand
plt.plot(t, fit_function(t, 20e13), label="guessed with 20 THz")
# plot lin fit of ln()
plt.plot(t,fit_lin(t,linfit_Params[0], linfit_Params[1]),
label=r"fitted $ln(\frac{I_{h00}}{I_0})$,"+ " w = {:.8} THz".format(linfit_Params[0]/1e12))
# plot exo fit
plt.plot(t, fit_function(t, fitParams[0]),
label=" calculated w={:.3}THz".format(fitParams[0]/1e12))
plt.legend(loc="best")
plt.show()