【发布时间】:2018-07-19 10:00:06
【问题描述】:
G = [100,200,300]
I_cel = [[0.1, 0.2,0.3,0.4],[1,2,3,4],[11, 22,33,44]]
for i in list(range(len(G))):
V_cel.append([])
Iph_g = Iph_cal[i]
Icel_g = I_cel[i]
for j in Icel_g:
a = math.log((Iph_g - j - I_sat)/I_sat,10) - j*R_se
V_cel[i].append(a)
print(V_cel[0])
** 输出为:ValueError: math domain error 输出中的箭头指向a = math.log((Iph_g - j - I_sat)/I_sat,10) - j*R_se。看起来它是一些数学错误的根源。一些帮助。当我设置a = i*j(检查整个程序)并且代码成功执行时,其他一切都很好。
【问题讨论】:
-
您应该再次使用地图和列表进行列表操作。
-
我已经编辑了这个问题。请看上面。整个代码工作正常。除了一些涉及
log函数的数学错误。当我通过设置a = i*j而不是log公式执行整个程序时,程序执行成功。我认为log函数有些问题。请帮忙。 -
对于 math.log(a,b),如果 a=0,它将返回一个数学域错误。从您的代码中,我看不到 I_sat 和 Iph_cal,我想这就是问题所在,这部分 "(Iph_g - j - I_sat)/I_sat" euqals o。
-
非常感谢您努力理解和分析错误原因。您确实认为计算导致了负值和数学错误的对数。我已经整理好了。
标签: python python-3.x for-loop