中南民族大学-通信工程2024-大学物理下实验
目录
- 代码实现
- 结果显示
🛠工具使用
MarsCode(插件,集成在PyCharm);
python编程(豆包AI智能体)
💻编程改进
此处是用「Matplotlib」来作图,时间有限未能完全还原老师的要求。后面将尝试用「Seaborn」 。
「Seaborn」 继承了「Matplotlib」 的强大功能,同时提供了更高级的接口和更美观的默认样式;而且易于使用,代码简洁。
代码实现
# 太阳能电池特性
import math
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
# 单晶硅
U = [0.0, 0.5, 1.0, 1.5, 2.0,
2.2, 2.4, 2.6, 2.8, 3.0,
3.2, 3.4, 3.6]
I1 = [0, 0.011, 0.022, 0.036, 0.051,
0.058, 0.066, 0.074, 0.083, 0.094,
0.107, 0.124, 0.145]
lnI1 = []
for i in range(len(I1)):
if i == 0:
continue
lnI = math.log(I1[i])
lnI1.append(lnI)
# print(f'{lnI:.2f}')
# 多晶硅
I2 = [0, 0.002, 0.005, 0.012, 0.023,
0.029, 0.036, 0.045, 0.055, 0.067,
0.082, 0.098, 0.116]
lnI2 = []
for i in range(len(I2)):
if i == 0:
continue
lnI2.append(math.log(I2[i]))
# print(
# f"i{i+1:<2} = {I2[i]} lnI{i+1:<2} = {lnI:.2f}"
# )
# 非晶硅
I3 = [0, 0.001, 0.006, 0.050, 0.140,
0.245, 0.396, 0.582, 0.807, 1.280,
2.7, 6.1, 12.9]
lnI3 = []
for i in range(len(I3)):
if i == 0:
continue
lnI3.append(math.log(I3[i]))
# print(
# f"i{i+1:<2} = {I3[i]} lnI{i+1:<2} = {lnI:.2f}"
# )
# 线性拟合求理想因子
# 转换为numpy数组
U = np.array(U[4:])
lnI1 = np.array(lnI1[3:])
lnI2 = np.array(lnI2[3:])
lnI3 = np.array(lnI3[3:])
# 绘制散点图
plt.subplot(3, 2, 2)
plt.scatter(U, lnI1, label='mc-Si')
plt.scatter(U, lnI2, label='pc-Si', marker='s')
plt.scatter(U, lnI3, label='a-Si', marker='^')
# 线性拟合
slope1, intercept1, r_value1, p_value1, std_err1 = stats.linregress(U, lnI1)
slope2, intercept2, r_value2, p_value2, std_err2 = stats.linregress(U, lnI2)
slope3, intercept3, r_value3, p_value3, std_err3 = stats.linregress(U, lnI3)
# 绘制线性拟合曲线
plt.plot(U, slope1 * U + intercept1, color='blue')
plt.plot(U, slope2 * U + intercept2, color='red')
plt.plot(U, slope3 * U + intercept3, color='green', linestyle='--')
plt.plot(U, lnI3, color='green')
# 添加图例和标签
plt.annotate(f"y={slope3:.2f}x{intercept3:.2f}\nR²={r_value3:.2f}", xy=(3.5, 1.6))
plt.annotate(f"y={slope2:.2f}x{intercept2:.2f}\nR²={r_value2:.2f}", xy=(3.5,-4))
plt.annotate(f"y={slope1:.2f}x{intercept1:.2f}\nR²={r_value1:.2f}", xy=(U[1],lnI1[1]))
plt.grid(True)
plt.title('Linear fitting for device\'s ideal factor')
plt.legend()
plt.xlabel('U/V')
plt.ylabel('lnI')
# 显示图形
print(f"Linear Fit Slope: {slope1} n:{26 / slope1}")
print(f"Linear Fit Slope: {slope2} n:{26 / slope2}")
print(f"Linear Fit Slope: {slope3} n:{26 / slope3}")
# 太阳能电池暗态伏安特性
# 转换为numpy数组
U = [0.0, 0.5, 1.0, 1.5, 2.0,
2.2, 2.4, 2.6, 2.8, 3.0,
3.2, 3.4, 3.6]
U = np.array(U)
ax1 = plt.subplot(3, 2, 1)
# 创建第一个 y 轴
ax1.scatter(U, I1, label='mc-Si') # 单晶硅
ax1.plot(U, I1) # 单晶硅
ax1.scatter(U, I2, marker='s',label='pc-Si')
ax1.plot(U, I2, ) # 多晶硅
ax1.set_xlabel('U/V')
ax1.set_ylabel('I/mA')
# 创建第二个 y 轴
ax2 = plt.twinx()
ax2.scatter(U, I3, color='green', marker='^', label='a-Si')
ax2.plot(U, I3, color='green') # 非晶硅
# 添加箭头
# ax2.annotate("",xy=(3.5,5), xytext=(U[-2],I3[-2]), arrowprops=dict(facecolor='black'))
ax1.grid(True)
lines, labels = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax2.legend(lines + lines2, labels + labels2, loc='upper left')
plt.title('Solar cell dark state voltage-current characteristic')
# 光照下太阳能电池输出特性
# 单晶硅
I11 = [0.061, 0.603, 1.492, 3.0, 5.8,
7.2, 9.4, 11.1, 13.5, 16.5,
20.0, 20.5, 20.5, 20.6, 20.8,
20.9, 21.2, 21.2, 21.3, 21.5]
U11 = [6.11, 6.05, 6.01, 5.95, 5.84,
5.77, 5.68, 5.61, 5.43, 5.00,
4.02, 2.06, 1.66, 1.25, 0.84,
0.43, 0.22, 0.14, 0.03, 0.01]
P1 = []
for i, u in zip(I11, U11):
p = i * u
# print(f"i = {i:.2f} U = {u:.2f} P = {p:.2f}")
P1.append(p)
# 多晶硅
I22 = [0.057, 0.573, 1.425, 2.7, 5.0,
6.2, 8.0, 9.4, 11.4, 14.4,
18.9, 24.3, 24.6, 24.7, 24.7,
24.7, 24.6, 24.5, 24.5, 24.4]
U22 = [5.78, 5.77, 5.75, 5.35, 5.07,
4.97, 4.82, 4.72, 4.58, 4.34,
3.80, 2.46, 1.994, 1.504, 1.01,
0.512, 0.264, 0.166, 0.04, 0.018]
P2 = []
for i, u in zip(I22, U22):
p = i * u
# print(f"i = {i:<5.2f} U = {u:.2f} P = {p:.2f}")
P2.append(p)
# 非晶硅
I33 = [0.031, 0.306, 0.760, 1.502, 3.0,
3.7, 4.8, 5.6, 6.7, 8.2,
9.6, 10.5, 10.6, 10.7, 10.6,
10.7, 10.6, 10.7, 10.8, 10.8]
U33 = [3.1, 3.08, 3.06, 3.03, 2.97,
2.93, 2.87, 2.81, 2.7, 2.47,
1.93, 1.06, 0.852, 0.69, 0.428,
0.22, 0.113, 0.072, 0.018, 0.008]
P3 = []
for i, u in zip(I33, U33):
p = i * u
# print(f"i = {i:<5.2f} U = {u:.2f} P = {p:.2f}")
P3.append(p)
# 输出功率和输出电压的关系
plt.subplot(3, 2, 5)
plt.scatter(U11, P1, label='mc-Si')
plt.plot(U11, P1)
plt.scatter(U22, P2, label='pc-Si', marker='s')
plt.plot(U22, P2)
plt.scatter(U33, P3, label='a-Si', marker='^')
plt.plot(U33, P3)
plt.grid(True)
plt.legend()
plt.title('Output power and output voltage relationship')
plt.xlabel('U/V')
plt.ylabel('P/mW')
# 光照下的太阳能电池输出特性
plt.subplot(3, 2, 6)
plt.scatter(U11, I11, label='mc-Si')
plt.plot(U11, I11)
plt.scatter(U22, I22, label='pc-Si', marker='s')
plt.plot(U22, I22)
plt.scatter(U33, I33, label='a-Si', marker='^')
plt.plot(U33, I33)
plt.grid(True)
plt.legend(loc='upper right')
plt.title('Output characteristics of solar cells under illumination')
plt.xlabel('U/V')
plt.ylabel('I/mA')
# 光照强度对开路电压的影响
I = [816, 323, 183, 122, 86, 67, 52, 42, 35, 29]
# 单晶硅
Uoc1 = [6.17, 5.82, 5.56, 5.41, 5.30, 5.22, 5.14, 5.08, 5.01, 4.96]
# 多晶硅
Uoc2 = [6.13, 5.82, 5.57, 5.40, 5.27, 5.18, 5.08, 5.01, 4.93, 4.86]
# 非晶硅
Uoc3 = [3.74, 3.38, 3.29, 3.22, 3.16, 3.11, 3.06, 3.01, 2.97, 2.93]
plt.subplot(3, 2, 3)
plt.scatter(I, Uoc1, label='mc-Si')
plt.plot(I, Uoc1)
plt.scatter(I, Uoc2, label='pc-Si', marker='s')
plt.plot(I, Uoc2)
plt.scatter(I, Uoc3, label='a-Si', marker='^')
plt.plot(I, Uoc3)
plt.grid(True)
plt.legend()
plt.title('Impact of light intensity on the open-circuit voltage')
plt.xlabel('I/(W/m²)')
plt.ylabel('Uoc/V')
# 光照强度对短路电流的影响
# 单晶硅
Isc1 = [53.3, 24.7, 16.8, 9.2, 6.8, 5.1, 4.1, 3.4, 2.9, 2.4]
# 多晶硅
Isc2 = [91.8, 36.3, 22.2, 15.3, 11.2, 8.6, 6.7, 5.4, 4.4, 3.7]
# 非晶硅
Isc3 = [38.4, 19.0, 10.7, 7.0, 5.0, 3.8, 2.9, 2.3, 1.9, 1.6]
plt.subplot(3, 2, 4)
plt.scatter(I, Isc1, label='mc-Si')
plt.plot(I, Isc1)
plt.scatter(I, Isc2, label='pc-Si', marker='s')
plt.plot(I, Isc2)
plt.scatter(I, Isc3, label='a-Si', marker='^')
plt.plot(I, Isc3)
plt.grid(True)
plt.legend()
plt.title('Impact of light intensity on the short-circuit current')
plt.xlabel('I/(W/m²)')
plt.ylabel('Isc/mA')
# 调整子图之间的间距
plt.subplots_adjust(hspace=0.5, wspace=0.3)
# 显示图形
plt.show()