Я пытаюсь найти постоянную времени для экспоненциальной кривой затухания, но мой код ниже не работает. Кто-нибудь может помочь? Спасибо!
from scipy.signal import lti
import pylab as plt
from scipy.optimize import curve_fit
import math as m
def model1(x, gain1, tau1):
y = lti(gain1, [tau1, 1]).step(T=x)[1]
return y
def get_time_constants(time_vector, power_vector):
time_constant = []
for i in range(len(power_vector)):
# fit to output and estimate parameters - gain and tau
par1 = curve_fit(model1, time_vector[i], power_vector[i])
print(par1)
y_fit = model1(time_vector[i], par1[0][0], par1[0][1])
time_constant.append(par1[0][1])
time_constant_mean = sum(time_constant) / len(time_constant)
plt.plot(time_vector[i], power_vector[i])
plt.plot(time_vector[i], y_fit, label='Time Constant: %.2f s' %par1[0][1])
plt.show()
power = [[315.04, 315.025, 275.255, 170.92, 65.89, 40.92, 25.38, 9.45, 5.835, 2.2, 1.335, 0.79, 0.24]]
time = [[0.0, 1.0, 3.0, 4.0, 5.0, 7.0, 8.0, 10.0, 11.0, 12.0, 14.0, 15.0, 17.0]]
get_time_constants(time, power)
![enter image description here](https://i.stack.imgur.com/OtaXF.png)