I'm trying to use curve fitting to fit to a function that takes in an array of frequencies as x-values. I keep getting this error and have tried to reshape and make my y-values floats. Not really sure where to go from here since I keep getting the error.
r_0 = (n_0 - n_1)/(n_0 + n_1)
r_1 = (n_1 - n_0)/(n_1+ n_0)
t_1 = 1 + r_1
t_0 = 1 + r_0
freq_values = np.linspace(108,200,1000)
#function to fit to
def T(freq,ghz=[]):
Transmittance = []
for ghz in freq_values:
X_01 = np.exp((2j*np.pi*0.004724*1.528*ghz*10**9)/(3*10**8))
H_1 = X_01 + r_0*r_1*(X_01)**-1
T = (t_0*t_1)/(H_1)
hola = list(T.flat)
Transmittance.append(hola*np.conj(hola))
return Transmittance
x = freq_values
y = T(freq_values)
yy= np.reshape(y, len(y))
yyy= np.array(yy.real, dtype=float)
plt.plot(x,y, 'r', label = 'calculated')
#fit function, want to match/find optimized n value
def TT(freq,n,ghz=[]):
Transmittance = []
for ghz in freq_values:
X_01 = np.exp((2j*np.pi*0.004724*n*ghz*10**9)/(3*10**8))
H_1 = X_01 + r_0*r_1*(X_01)**-1
T = (t_0*t_1)/(H_1)
hola = list(T.flat)
Transmittance.append(hola*np.conj(hola))
return Transmittance
popt, pcov = curve_fit(TT, x, yyy) #ydata = power (transmission) data
plt.plot(x, TT(x, *popt), 'b', label = 'fit')
plt.legend(loc='upper right')
I expect the code or fit to match the original plot but keep getting an error for yyy in curve_fit(TT,x,yyy)