Exploring Series Sum Programs in Python with Emancipation Edutech

Welcome to another insightful blog by Emancipation Edutech, Ranchi. Today, we will delve into some fundamental Python programs designed to find the sum of different mathematical series. These programs not only enhance your coding skills but also provide a deeper understanding of loops, arithmetic operations, and the power of Python in solving mathematical problems.

Program 1: Sum of a Series

Problem Statement

Write a program to find the sum of the following series:

  s = x \times 2 + x \times 4 + x \times 6 + \ldots + x \times 2n

Python Code

Python
# Program to find the sum of the series x * 2 + x * 4 + x * 6 + ... + x * 2n

x = float(input("Enter a number: "))
n = int(input("Enter limit: "))
s = 0 

for i in range(1, n + 1):
    s = s + x * (2 * i)

print("The sum of the series is:", s)

Explanation

  1. Input: The user provides a number x and a limit n.
  2. Initialization: We initialize the sum s to 0.
  3. Loop: The loop runs from 1 to n, calculating x * (2 * i) for each iteration and adding it to s.
  4. Output: Finally, the sum s is printed.

Sample Output

Enter a number: 2
Enter limit: 3
The sum of the series is: 24.0

Program 2: Sum of a Series Involving Reciprocals

Problem Statement

Write a program to find the sum of the following series:
 \frac{1}{x^2} + \frac{1}{x^4} + \frac{1}{x^6} + \ldots + \frac{1}{x^{2n}}

Python Code

Python
# Program to find the sum of the series 1/x^2 + 1/x^4 + 1/x^6 + ... + 1/x^2n

x = float(input("Enter a number: "))
n = int(input("Enter limit: "))

s = 0
for i in range(2, 2*n + 2, 2):
    s = s + 1 / x**i

print("The sum of the series is:", s)

Explanation

  1. Input: The user inputs a number x and a limit n.
  2. Initialization: We initialize the sum s to 0.
  3. Loop: The loop runs from 2 to 2n+2 in steps of 2, calculating 1 / x**i for each i and adding it to s.
  4. Output: The sum s is printed.
See also  Understanding Type Hints in Python

Sample Output

Enter a number: 2
Enter limit: 3
The sum of the series is: 0.3125

Program 3: Sum of Incremental Series

Problem Statement

Write a program to find the sum of the following series:
 1 + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3 + 4) + \ldots + (1 + 2 + 3 + 4 + \ldots + n)

Python Code

Python
# Program to find the sum of the series 1 + (1 + 2) + (1 + 2 + 3) + ... + (1 + 2 + 3 + ... + n)

n = int(input("Enter limit: "))

s = 0
for i in range(1, n + 1):
    s = s + (i * (i + 1)) // 2

print("The sum of the series is:", s)

Explanation

  1. Input: The user inputs a limit n.
  2. Initialization: We initialize the sum s to 0.
  3. Loop: The loop runs from 1 to n. For each i, the sum of the first i natural numbers is added to s.
  4. Output: The sum s is printed.

Sample Output

Enter limit: 4
The sum of the series is: 20

Visual Representation

Sum of Series 1:  x * 2 + x * 4 + x * 6 + … + x * 2n

Here’s a chart representing how the sum changes as n increases for a fixed x:

Python
import matplotlib.pyplot as plt

x = 2
n_values = range(1, 11)
s_values = [sum(x * (2 * i) for i in range(1, n + 1)) for n in n_values]

plt.plot(n_values, s_values, marker='o')
plt.title('Sum of Series: x * 2 + x * 4 + x * 6 + ... + x * 2n')
plt.xlabel('n')
plt.ylabel('Sum')
plt.grid(True)
plt.show()

Sum of Series 2:  1/x^2 + 1/x^4 + 1/x^6 + … + 1/x^2n

A chart representing the sum for different values of x:

Python
x_values = [2, 3, 4]
n = 5
s_values = [[sum(1 / x**i for i in range(2, 2*n + 2, 2)) for x in x_values] for n in range(1, 6)]

for idx, x in enumerate(x_values):
    plt.plot(range(1, 6), [s[idx] for s in s_values], marker='o', label=f'x={x}')

plt.title('Sum of Series: 1/x^2 + 1/x^4 + 1/x^6 + ... + 1/x^2n')
plt.xlabel('n')
plt.ylabel('Sum')
plt.legend()
plt.grid(True)
plt.show()

Conclusion

These programs provide a clear understanding of how to handle series in Python using loops and arithmetic operations. Emancipation Edutech in Ranchi is dedicated to empowering students with such practical programming knowledge. If you are keen to learn more about Python and enhance your coding skills, visit our website or contact us at teamemancipation@gmail.com.

See also  Exception Handling in Python

Keywords: Python Series Programs in Ranchi, Learn Python in Ranchi, Emancipation Edutech Ranchi, Python Courses in Ranchi

Contact Us:

  • Company Name: Emancipation Edutech Private Limited
  • Contact Number: +919264477176
  • Website: emancipation.co.in
  • Email ID: teamemancipation@gmail.com
  • Address: Abhinandan Complex, Tharpakhna, Near Govt. Women’s Polytechnic, Ranchi, Jharkhand.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top