154k views
2 votes
Write an algorithm to find the sum of the following series:

a) 1+x+x^2+x^3+...+x^20
b) 1-x+x^2-x^3+...+x^20
c) 1+x/2+(x²)/3+(x^3)/4+...+(x^20)/21

User Abeger
by
7.1k points

1 Answer

6 votes

Answer:

The algorithm is as follows:

Input x

sum_a = 0

sum_b = 0

sum_c = 0

for i = 0 to 20

sum_a = sum_a + x^i

sum_b = sum_b + (-x)^i

sum_c = sum_c + x^i/(i+1)

print sum_a, sum_b, sum_c

Step-by-step explanation:

Required

An algorithm to solve (a), (b) and (c)

For Series (a):

This series is a geometric progression and the common ratio is x

i.e.


r = x/1 = x^2/x = ...... = x^(n+1)/x^n =x

So, the sum of the series is:

Sum = Previous Sums + x^i --- where i is between 0 and 20 (inclusive)

For Series (b):

This series is a geometric progression and the common ratio is -x

i.e.


r = -x/1 = -x^2/x = ...... = -(x^(n+1)/x^n) = -x

So, the sum of the series is:

Sum = Previous Sums + (-x^i) --- where i is between 0 and 20 (inclusive)

For Series (c):

This series is a neither arithmetic nor geometric progression.

It obeys the following rule:


(x^i)/(1+i) --- where i is between 0 and 20 (inclusive)

So, the sum of the series is:

Sum = Previous Sums +
(x^i)/(1+i)

User Jrad
by
6.8k points