# Find the sum of infinite series 1^2.x^0 + 2^2.x^1 + 3^2.x^2 + 4^2.x^3 +…….

Given an infinite series and a value x, the task is to find its sum. Below is the infinite series

1^2*x^0 + 2^2*x^1 + 3^2*x^2 + 4^2*x^3 +……. upto infinity, where x belongs to (-1, 1)

**Examples:**

Input: x = 0.5 Output: 12 Input: x = 0.9 Output: 1900

**Approach:**

Though the given series is not an Arithmetico-Geometric series, however, the differences and so on, forms an AP. So, we can use the Method of Differences.

Hence, the sum will be **(1+x)/(1-x)^3.**

**Below is the implementation of above approach:**

## C++

`// C++ implementation of above approach ` `#include <iostream> ` `#include <math.h> ` ` ` `using` `namespace` `std; ` ` ` `// Function to calculate sum ` `double` `solve_sum(` `double` `x) ` `{ ` ` ` `// Return sum ` ` ` `return` `(1 + x) / ` `pow` `(1 - x, 3); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// declaration of value of x ` ` ` `double` `x = 0.5; ` ` ` ` ` `// Function call to calculate ` ` ` `// the sum when x=0.5 ` ` ` `cout << solve_sum(x); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to find ` `//sum of the given infinite series ` `import` `java.util.*; ` ` ` `class` `solution ` `{ ` `static` `double` `calculateSum(` `double` `x) ` `{ ` ` ` `// Returning the final sum ` `return` `(` `1` `+ x) / Math.pow(` `1` `- x, ` `3` `); ` ` ` `} ` ` ` `//Driver code ` `public` `static` `void` `main(String ar[]) ` `{ ` ` ` ` ` `double` `x=` `0.5` `; ` ` ` `System.out.println((` `int` `)calculateSum(x)); ` ` ` `} ` `} ` `//This code is contributed by Surendra_Gangwar ` |

*chevron_right*

*filter_none*

## Python

`# Python implementation of above approach ` ` ` `# Function to calculate sum ` `def` `solve_sum(x): ` ` ` `# Return sum ` ` ` `return` `(` `1` `+` `x)` `/` `pow` `(` `1` `-` `x, ` `3` `) ` ` ` `# driver code ` ` ` `# declaration of value of x ` `x ` `=` `0.5` ` ` `# Function call to calculate the sum when x = 0.5 ` `print` `(` `int` `(solve_sum(x))) ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find sum of ` `// the given infinite series ` `using` `System; ` ` ` `class` `GFG ` `{ ` `static` `double` `calculateSum(` `double` `x) ` `{ ` ` ` `// Returning the final sum ` `return` `(1 + x) / Math.Pow(1 - x, 3); ` ` ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `double` `x = 0.5; ` ` ` `Console.WriteLine((` `int` `)calculateSum(x)); ` `} ` `} ` ` ` `// This code is contributed ` `// by inder_verma.. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of ` `// above approach ` ` ` `// Function to calculate sum ` `function` `solve_sum(` `$x` `) ` `{ ` ` ` `// Return sum ` ` ` `return` `(1 + ` `$x` `) / ` ` ` `pow(1 - ` `$x` `, 3); ` `} ` ` ` `// Driver code ` ` ` `// declaration of value of x ` `$x` `= 0.5; ` ` ` `// Function call to calculate ` `// the sum when x=0.5 ` `echo` `solve_sum(` `$x` `); ` ` ` `// This code is contributed ` `// by inder_verma ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

12

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Sum of series M/1 + (M+P)/2 + (M+2*P)/4 + (M+3*P)/8......up to infinite
- Find if the given number is present in the infinite sequence or not
- Find the count of unvisited indices in an infinite array
- Find minimum moves to reach target on an infinite line
- Find the sum of the series x(x+y) + x^2(x^2+y^2) +x^3(x^3+y^3)+ ... + x^n(x^n+y^n)
- Find sum of the series 1-2+3-4+5-6+7.......
- Find the sum of the series 2, 5, 13, 35, 97...
- Find the sum of series 3, 7, 13, 21, 31....
- Find the sum of first N terms of the series 2×3 + 4×4 + 6×5 + 8×6 + ...
- Find Nth term of the series 1, 8, 54, 384...
- Find nth term of the series 5 2 13 41
- Find Nth term of the series 1, 6, 18, 40, 75, ....
- Find Nth term of the series 1, 5, 32, 288 ...
- Find n-th term of series 1, 3, 6, 10, 15, 21...
- Find the nth term of the given series
- Find n-th term in series 1 2 2 3 3 3 4 4 4 4....
- Find Nth term of the series 3, 14, 39, 84...
- Find the Nth term of the series 2 + 6 + 13 + 23 + . . .
- Find the last digit of given series
- Find n-th term of series 3, 9, 21, 41, 71...

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.