Sum of n terms of a sequence
Last Updated :
14 Feb, 2022
If nth term of a sequence is given by Tn=an3+bn2+cn+d where a, b, c, d are constants then sum of n terms.
Sn = a*Σ(n3)+b*Σ(n2)+c*Σ(n)+Σ(d)
where Σ represent summation.
Proof :
Let us find some of this series. So,
Sn = T1+T2+T3+T4+ ... +Tn
T1 = a(1)3+b(1)2+c(1)+d
T2 = a(2)3+b(2)2+c(2)+d
T3 = a(3)3+b(3)2+c(3)+d
...
...
Tn = a(n)3+b(n)3+c(n)+d
adding these all terms,
Sn
= T1+T2+T3+ ... +Tn
= a((1)3+(2)3+(3)3+ ...
+(n)3)+b((1)2+(2)2+(3)2+ ...
+(n)2)+c(1+2+3+ ... +n)+d(1+1+1+ ... +1)
Sn = a*Σ(n3)+b*Σ(n2)+c*Σ(n)+dn
Similarly if we have been nth term for any higher order or lower order term in the format.
Tn = a1np+a2np-1+a3np-2++
... +apn1+ap+1
Sn = a1Σ(np)+a2Σ(np-1)+a3Σ(np-2)+
... +apΣ(n)+nap+1
where p, a1, a2, …… are some constants.
Example :
nth term is given as,
Tn = n2+n+1
Calculate Sn
Explanation :
Sn = Σ(Tn)
Sn = Σ(n2)+Σ(n)+Σ(1)
Sn = (n(n+1)(2n+1))/6+n(n+1)/2+n
Because,
Σ(n2) = (n(n+1)(2n+1))/6,
Σ(n) = (n(n+1))/2,
Σ(1) = n
Thus we can find sum of any sequence if its nth term is given. This article is helpful in finding time complexity of equations when time complexity is given as function of n and we have to find the time complexity for the whole algorithm.
CPP14
#include <bits/stdc++.h>
using namespace std;
int main()
{
int k = 3;
int sum = 0;
for ( int i = 1; i <= k; i++)
sum += (i * i * i * i);
sum += (k * (k + 1)) / 2;
sum += k;
cout << sum << endl;
}
|
Python3
k = 3
sum = 0
for i in range ( 1 , k + 1 ):
sum + = (i * i * i * i)
sum + = (k * (k + 1 )) / 2
sum + = k
print ( int ( sum ))
|
Output :
107
The given code above finds summation of sequence for 3 terms in which,
Tn = n4+n+1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...