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:
Python Code
# 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
- Input: The user provides a number
x
and a limitn
. - Initialization: We initialize the sum
s
to 0. - Loop: The loop runs from 1 to
n
, calculatingx * (2 * i)
for each iteration and adding it tos
. - 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:
Python Code
# 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
- Input: The user inputs a number
x
and a limitn
. - Initialization: We initialize the sum
s
to 0. - Loop: The loop runs from 2 to
2n+2
in steps of 2, calculating1 / x**i
for eachi
and adding it tos
. - Output: The sum
s
is printed.
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:
Python Code
# 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
- Input: The user inputs a limit
n
. - Initialization: We initialize the sum
s
to 0. - Loop: The loop runs from 1 to
n
. For eachi
, the sum of the firsti
natural numbers is added tos
. - Output: The sum
s
is printed.
Sample Output
Enter limit: 4
The sum of the series is: 20
Visual Representation
Sum of Series 1:
Here’s a chart representing how the sum changes as n
increases for a fixed x
:
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:
A chart representing the sum for different values of x
:
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.
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.