A
A
Anna Panova2021-06-18 16:56:11
Python
Anna Panova, 2021-06-18 16:56:11

Calculate the sum of a series with a given precision?

Hello! Please help me understand what is the problem.

*The same number is constantly displayed without stopping*

The task sounds like this: Given real numbers x, ε (x≠0, ε>0) and an integer n. Calculate with precision ε: latex.cgi?%5Csum_%7Bk%3D1%7D%5E%7B%5Cinfty%20%7D%20%3D%20%5Cfrac%7B%5Csqrt%7B%5Cleft%7Cx%20%5Cright%7C%7D%7D %7B%7Bk%7D%5E%7B3%7D%7D
Here is my code:

import math

x = float(input("x ="))
e = float(input("e = "))
n = float(input("n = "))
S = 0


if x != 0 and e > 0:
    i = 1
    while i <= n:
        chlen = math.sqrt(math.fabs(x))/n**3
        if S + chlen < e:
            S = S + chlen
        else:
            print(S)
else:
    print("попробуйте еще раз")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2021-06-18
@vegetable00

Let's go here .
We specify the value ζ(3)≈1.2021 .
Writing a one-liner

from math import fabs, sqrt
print(1.2020569031595942 * sqrt(fabs(x)))
which gives a relative error of ~1e-16. We rest, we think at leisure, why the hell was n
given in the condition .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question