我正在尝试编写一个嵌套循环,以便根据时间 (t) 计算温度 (te) 的多个值,每个值都使用不同的时间步长 (dt)。
dt_values = [0.05, 0.025, 0.1, 0.05, 0.001]
for j in dt_values:
t = np.arange(0,100,[j])
te = np.zeros(len(t))
te[0] = te_init
dt = j
def f(te):
y = -r*(te - te_surr) # y is the derivative
return y
for i in range(1,len(t)):
te[i] = te[i-1] + f(te[i-1])*[j]
plt.plot(t, te)
但是,我收到以下错误消息:
t = np.arange(0,100,[j])
类型错误:不支持 / 的操作数类型:'int' 和 'list'
那么,在创建 t 数组时不能像我那样使用列表?我不能使用,例如
对于范围内的 j ...
由于我对 dt 的值不是均匀分开的。所以,我想知道,是否有另一种定义 np.arange 支持的 dt_values 的方法?
step 参数应该是 int 而不是列表。将 [j] 更改为 j
有关numpy.arange 的更多信息
dt_values = [0.05, 0.025, 0.1, 0.05, 0.001]
for j in dt_values:
t = np.arange(0,100,j)
te = np.zeros(len(t))
te[0] = te_init
dt = j
def f(te):
y = -r*(te - te_surr) # y is the derivative
return y
for i in range(1,len(t)):
te[i] = te[i-1] + f(te[i-1])*[j]
plt.plot(t, te)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句