我正在尝试编写一个执行以下操作的程序:
>从数组中获取V的值
>将V值传递给相对于E的积分
>将积分结果输出到数组I中
>情节I对抗V
这个等式看起来很讨厌,但除了V. Here is the equation之外,一切都是常数.这个等式并不是很重要.
我应该怎么解决这个问题?我的尝试(如下所示)不计算从文件中读取的每个V值的积分.
from scipy import integrate #integrate.quad
from numpy import *
import pylab
import datetime
import time
import os
import math
# import V
fn = 'cooltemp.dat'
V = loadtxt(fn,unpack=True,usecols=[1])
# variables
del1, del2, R, E, fE, fEeV = 1,2,1,2,1,1
e = 1.602176565*10**-19
# eqn = dint(abc)
a = E/( math.sqrt( E**2 - del1**2 ) )
b = ( E+ e*V )/( math.sqrt( ( E + e*V )**2) - del2**2)
c = fE-fEeV
d = 1/(e*R) # integration constant
eqn = a*b*c
# integrate
result = quad(lambda E: eqn,-inf,inf)
# current
I = result*d
# plot IV curve
pylab.plot(V,I,'-r')
## customise graph
pylab.legend(['degree '+str(n),'degree '+str(q),'data'])
pylab.axis([0,max(x),0,max(y)])
pylab.xlabel('voltage (V)')
pylab.ylabel('current (A)')
tc = datetime.datetime.fromtimestamp(os.path.getmtime(fn))
pylab.title('IV curve
'+fn+'
'+str(tc)+'
'+str(datetime.datetime.now()))
pylab.grid(True)
pylab.show()
*更新尝试:
from scipy import integrate
from numpy import *
import pylab
import datetime
import time
import os
import math
# import V
fn = 'cooltemp.dat'
V = loadtxt(fn,unpack=True,usecols=[1])
# print V
# variables
del1, del2, R, E, fE, fEeV = 1.0,2.0,1.0,2.0,1.0,1.0
e = 1.602176565*10**-19
I=[]
for n in range(len(V)):
constant = 1/(e*R) # integration constant
eqn = (E/( math.sqrt( E**2 - del1**2 ) ))*(( E + e*V[n] )/( math.sqrt( ( E + e*V[n] )**2) - del2**2))*(fE-fEeV)
# integrate
result,error = integrate.quad(lambda E: eqn,-inf,inf)
print result
# current
I.append(result*constant)
I = array(I)
# plot IV curve
pylab.plot(V,I,'-b')