In [367]:
import scipy.optimize as opt
import numpy as np
import csv
import matplotlib.pyplot as plt
from scipy.odr import *
def fit_f(i, n, i0, r):
return n * 1.38e-23 * 300 * (1 / 1.6e-19) * np.log(i/i0 + 1) + r*i
def odr_f(beta, x):
return beta[0] * 1.38e-23 * 300 * (1 / 1.6e-19) * np.log(x/beta[1] + 1) + beta[2]*i
In [368]:
with open("amp3", 'r') as fil:
count = len(fil.readlines())
u_amp = np.zeros(count)
su_amp = np.zeros(count)
u_led = np.zeros(count)
su_led = np.zeros(count)
csvreader = csv.reader(fil, delimiter='\t')
print(csvreader)
i = 0
fil.seek(0)
for row in csvreader:
if(row[0] == ''):
continue
print(row)
u_led[i]= float(row[1])
u_amp[i] = float(row[0])
su_amp[i] = float(row[3])
su_led[i] = float(row[2])
i += 1
In [371]:
ch1 = 2
ch2 = 1e-15
ch3 = 10
#adj = opt.curve_fit(fit_f, u_amp, u_led, sigma=su_led, p0=[ch1,ch2,ch3])
model = Model(odr_f)
data = RealData(u_amp, u_led, sx=su_amp, sy=su_led)
odr = ODR(data, model, [ch1, ch2, ch3])
output = odr.run()
output.pprint()
In [372]:
output.beta
Out[372]:
In [373]:
n = output.beta[0]
i0 = output.beta[1]
r = output.beta[2]
x = np.linspace(0, 3e-2, 1e6)
ohm = r*x
diode = fit_f(x, n, i0, r)
plt.plot(x, ohm, x, diode, x, ohm+diode)
plt.show()
In [363]:
output.beta[0]
Out[363]:
In [231]:
fit2=adj
In [233]:
fit1
Out[233]:
In [234]:
fit2
Out[234]:
In [239]:
cor2=fit2[1]
In [240]:
cor2[0][0]*cor2[1][1]*cor2[2][2]
Out[240]:
In [374]:
output.beta[0] * 1.38e-23 * 300 * (1 / 1.6e-19)
Out[374]:
In [375]:
1/output.beta[1]
Out[375]:
In [376]:
output.beta[2]
Out[376]:
In [4]:
1.38e-23 * 300 * (1 / 1.6e-19) * 2
Out[4]:
In [5]:
1e12
Out[5]:
In [ ]: