迭代函数的参数

问题描述 投票:0回答:1

我有这个代码,我想计算 0 < t < pi with 0.05 step, but each new function is a function of the previous one, and I can't really think of an easy way to iterate over it, any tips?

wf_0 = get_wf_0(xmin, xmax, Nx, neigs, t=0) #Ignore this since it's another function
wf_1 = get_wf(xmin, xmax, Nx, neigs, t=0.05 , wf = wf_0)
wf_2 = get_wf(xmin, xmax, Nx, neigs, t=0.1 , wf = wf_1)
wf_3 = get_wf(xmin, xmax, Nx, neigs, t=0.15 , wf = wf_2)

依此类推直到 t = pi

python function loops
1个回答
0
投票

基本上可以这样完成:

wf = get_wf_0(xmin, xmax, Nx, neigs, t=0)

for s in range(1, math.pi // 0.05):
    wf = get_wf(xmin, xmax, Nx, neigs, t=0.05 * s , wf = wf)
© www.soinside.com 2019 - 2024. All rights reserved.