我想在Python中绘制一个方程图,它在某些函数形式的两侧都有一个解决方案变量。 等式是:
i = Ip - Io*(exp((V+i*R1)/(n*Vt)) - 1) - (V +I*R1)/(R2)
其中Ip, Io, n, R1, R2, Vt
是一些常量。
我想在V
范围内迭代(0,10)
,并希望使用Python获取i
的值并绘制V-i
图。
import numpy as np
from sympy import *
import matplotlib.pyplot as plt
r = 50
V = np.linspace(0,10,r)
def current():
current = []
for t in V:
i = np.zeros(r)
Ipv = 3
Rs = 0.221
Rsh = 415
n = 2
m = 1.5
T = 302
Eg = 1.14
K = 1.3
Vt = T/11600
Io = K*(T**m)*exp(-Eg/(n*Vt))
i = Ipv - Io *(exp((t + Rs*i)/(n*Vt)) - 1) - (t + Rs * i)/Rsh
current.append(i)
return np.array(current)
Icurrent = current()
plt.plot(V,Icurrent)
plt.show()
我这样做了但这不起作用。
欢迎任何建议。
答案 0 :(得分:1)
看来,您的问题是您将numpy
数组与标量math
函数混合在一起。 Don't do this.用适当的numpy
函数替换它:
import numpy as np
import matplotlib.pyplot as plt
r = 50
V = np.linspace(0,10,r)
print(V)
def current():
current = []
for t in V:
i = np.zeros(r)
Ipv = 3
Rs = 0.221
Rsh = 415
n = 2
m = 1.5
T = 302
Eg = 1.14
K = 1.3
Vt = T/11600
Io = K*(T**m)*np.exp(-Eg/(n*Vt))
i = Ipv - Io *(np.exp((t + Rs*i)/(n*Vt)) - 1) - (t + Rs * i)/Rsh
current.append(i)
return np.array(current)
Icurrent = current()
plt.plot(V,Icurrent)
plt.show()
我建议使用scipy.fsolve
,但看起来你的方法正在发挥作用。