网站首页 网站地图
网站首页 > 电商创业 > 等比数列求和

等比数列求和

时间:2026-03-21 01:15:16

等比数列的求和公式为:

\[ S_n = a_1 \times \frac{1 - q^n}{1 - q} \]

其中:

\( S_n \) 是数列的前 \( n \) 项和,

\( a_1 \) 是数列的第一项,

\( q \) 是公比,

\( n \) 是项数。

这个公式适用于公比 \( q

eq 1 \) 的情况。如果 \( q = 1 \),则数列中每一项都相等,前 \( n \) 项和就是 \( n \times a_1 \)。

示例

假设有一个等比数列,首项 \( a_1 = 2 \),公比 \( q = 2 \),要求前 10 项的和。

\[ S_{10} = 2 \times \frac{1 - 2^{10}}{1 - 2} \]

\[ S_{10} = 2 \times \frac{1 - 1024}{-1} \]

\[ S_{10} = 2 \times (-1023) \]

\[ S_{10} = 2046 \]

所以,这个等比数列前 10 项的和是 2046。

代码示例

```python

def geometric_series_sum(a, q, n):

return a * (1 - qn) / (1 - q)

a = 2

q = 2

n = 10

sum_n = geometric_series_sum(a, q, n)

print("The sum of the first {} terms of the geometric series is: {}".format(n, sum_n))

```

输出结果为:

```

The sum of the first 10 terms of the geometric series is: 2046

```

这个公式和示例展示了如何快速计算等比数列的前 \( n \) 项和。