Python:根据较小函数的迭代构造较大的三角函数

Python: construct a larger trigonometric function based on iteration of smaller function

你好

我有函数 y = sin (x*b(i)+a(i))。 我想创建一个新函数 f,它是此 y 函数第 n 次迭代的产物,其中 i 作为迭代器。

f = y(I=1)*y(I=2)*y(I=3)

如何在 python 中创建这样的 f?

请注意,b(i) 和 a(i) 并不简单,例如b = I^2 和 a=3i。他们有 if 语句,据我所知,我需要将它们放在我的 y 函数之外。 假设它们是:

b: if i%2 == 0:
      b = I^2+2
   else
      b = 3

a: if i/3 = int(I/3):
      b = 5i
   else
      b = 0

这里的目标是我可以只更改变量 I,然后得到一个 f 函数,它是 y 函数与 I 迭代的乘积。然后我可以使用 f 函数找到 x 的新值。

(希望我的非专业漫谈有意义)

**编辑:这段代码解决了我的问题:**

import math

def a(i):
    if i/3 == int(i/3):
        out = 5 * i
    else:
        out = 1 
    return out

def b(i):
    if i%2 == 0:
        out = (i^2)+2
    else:
        out = 3
    return out

def y(x, i):
    return x * b(i) + a(i)

def f(x, i):
    accum = 1
    for iterations in range(i):
        accum *= y(x, iterations + 1)
    return accum

print f(3,5)

我建议您熟悉 Python 语法,这样您就可以 post 您尝试过的示例 运行ning 代码,或者至少显示错误你已经 运行 了。您 post 编辑的代码不会 运行,因为它不是 Python 代码。

Spelling/capitalization/indentation 都算了。

我不能完全按照你的要求去做,但这是我能弄清楚的最接近的,你应该可以从这里进行调整。

def a(i):
    if i/3 = int(i/3):
      out = 5 * i
   else
      out = 0

def b(i):
   if i%2 == 0:
       out = I^2+2
   else:
       out = 3
    return out

def y(x, i):
    return x * b(i) + a(i)

def f(x, i):
    accum = 1
    for iterations in range(i):
        accum *= y(x, iterations + 1)
    return accum