forked from horychen/ACMSIMC_TUT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noloadtest.py
47 lines (36 loc) · 1.25 KB
/
noloadtest.py
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
import pandas as pd
df = pd.read_csv('./noload.dat', header=None)
print(df)
from pylab import plt, np
x = np.array(df[3].values)**2
y = df[5].values
# The first two points are not in no-load condition
x = x[2:]
y = y[2:]
print(x,y)
# The first several points in no-load condition are not really in linear region due to leakage inductance
x = x[9:] # 多使用低电压的点,可以对线性部分进行更准确地拟合
y = y[9:] # 多使用低电压的点,可以对线性部分进行更准确地拟合
y += 100 # [W] friction and windage loss
print(x,y)
plt.plot(x, y, 'ko-')
import statsmodels.api as sm
# Ordinary least squares regression
print('Start OLS...')
model_Simple = sm.OLS(y, x).fit()
print(model_Simple.summary())
print('Parameters: ', model_Simple.params)
# Add a constant term like so:
print('\n', '-'*40)
print('Start OLS with a constant term (intercept)...')
model = sm.OLS(y, sm.add_constant(x)).fit()
print(model.summary())
print('Parameters: ', model.params)
x = [0] + x.tolist()
print(x)
plt.plot(x, np.array(x)*model_Simple.params[0], 'bs--')
plt.plot(x, np.array(x)*model.params[1] + model.params[0], 'rs--')
plt.xlabel('Voltage Squared [$\\rm V^2$]')
plt.ylabel('Power [W]')
plt.grid()
plt.show()