(Sum series) Write a recursive function to compute the following series:
m(i) = 1/3 + 2/5 + 3/7 +4/9 + 5/11 + 6/13 + ..........+ i / 2i + 1
Write a test program that displays m(i) for i 1, 2, ..., 10.
Sum Series Program Code:
#Recursive function 'computeSeries' to compute the
#series m(i) = 1/3 + 2/5 + 3/7 + ... + i / (2*i + 1).
def computeSeries(i):
# Base case: If i is 1,
#return the base value of the series.
if i == 1:
return 1 / 3.0
# Recursive case: Compute the sum of the
#series up to i-1 and add i / (2*i + 1).
return computeSeries(i - 1) + i / (2 * i + 1)
# Test program to display m(i) for i = 1 to 10.
for i in range(1, 11):
result = computeSeries(i)
print(f"m({i}) = {result:.4f}")
Executed Output:
m(1) = 0.3333
m(2) = 0.7333
m(3) = 1.1619
m(4) = 1.6063
m(5) = 2.0609
m(6) = 2.5224
m(7) = 2.9891
m(8) = 3.4597
m(9) = 3.9334
m(10) = 4.4096