Реализовать итерационную функцию на python3 с рядами

Рейтинг: 0Ответов: 1Опубликовано: 28.04.2023

Задание

Не получается реализовать, прикладываю код, но он работает не правильно

import math


def main(n, p, a, b):
    result = 0
    term = 0
    for c in range(1, p + 1):
        product = 1
        chislo = ((math.fabs(c ** 3)) ** 3) / 18 + math.fabs(p) + math.cos(40 * c ** 2 - 92 * c - 37) ** 2
        summation = 0
        summation += chislo
        product *= summation
        result += product
        for c in range(1, b + 1):
            for i in range(1, a + 1):
                for j in range(1, n + 1):
                    chislo2 = math.atan(33*j) + (20*p**2 - i)**7 + ((math.atan(i - c**3))**3) / 35
                    term = term + chislo2
    result += term
    return result

print(main(3, 0.76, 4, 6))

Ответы

▲ 0Принят
import math
def main(n, p, a, b):
    result = 0
    term = 0
    for c in range(1, n + 1):
        product = 1
        chislo = ((math.fabs(c ** 3)) ** 3) / 18 + math.fabs(p) + math.cos(40 * c ** 2 - 92 * c - 37) ** 2
        summation = 0
        summation += chislo
        product *= summation
        result += product
    for c in range(1, b + 1):
        for i in range(1, a + 1):
            for j in range(1, n + 1):
                chislo2 = math.atan(33*j) + (20*p**2 - i)**7 + ((math.atan(i - c**3))**3) / 35
                term = term + chislo2
    result += term
    return result

print(main(3, 0.76, 4, 6))
# 478226525.3071769
print(main(6, -0.66, 7, 5))
# 75592857.58437662
print(main(6, 0.18, 4, 6))
# 498479.95376054774
print(main(7, 0.61, 6, 5))
# 25401244.03990129
print(main(4, -0.35, 2, 6))
# 16083.069689305854