问题
求 1^2 + 2^2 + 3^2 + 4^2 + ... + n^2 = ?
解决思路
去掉之前乱七八糟的尝试
采用二元一次方程的方式进行代入计算
第一个二元一次方程
假设:sum = 1^2 + 2^2 + 3^2 + 4^2 + ... + n^2 将其看做一个整体看
假设:sum2 = 1^2 + 2^2 + 3^2 + 4^2 + ... + n^2 + (n + 1)^2 + (n + 2)^2 + ... + (n + n)^2
sum2 = sum + (n + 1)^2 + (n + 2)^2 + ... + (n + n)^2
= sum + (n^2 + 2n * 1 + 1^2) + (n^2 + 2n * 2 + 2^2) + ... (n^2 + 2n * n + n^2) // 为了方便理解将公式拆解成相同样式
= sum + n * n^2 + 2n * (1 + 2 + 3 ... + n) + (1^ 2 + 2^2 + 3^2 + ... + n^2)
= sum + n^3 + 2n * (1 + n) * n / 2 + sum
= 2sum + n^3 + n^3 + n^2
= 2sum + 2n^3 + n^2
第二个二元一次方程
切换计算方式
sum2 = 1^2 + 3^2 + 5^2 + ... + (2n - 1)^2 + 2^2 + 4^2 + 6^2 + ... (2n)^2
计算 sub = 2^2 + 4^2 + 6^2 + ... (2n)^2
sub = 2^2 + 4^2 + 6^2 + ... (2n)^2
= (2^2 * 1^2) + (2^2 * 2^2) + (2^2 * 3^2) + ... (2^2 * n^2)
= 2^2 * (1^2 + 2^2 + 3^2 + ... + n^2)
= 4sum
计算sub2 = 1^2 + 3^2 + 5^2 + ... + (2n - 1)^2
sub2 = 1^2 + 3^2 + 5^2 + ... + (2n - 1)^2
= (2 - 1)^2 + (4 - 1)^2 + (6 - 1)^2 + ... (2n - 1)^2
= (2^2 - 2 * 2 + 1) + (4^2 - 2 * 4 +1) + (6^2 - 2 * 6 + 1) + ... + ((2n)^2 - 2 * 2n + 1)
= (2^2 + 4^2 + 6^2 + (2n)^2) - 2 * 2 (1 + 2 + 3 + ... + n) + 1 * n
= 4sum - 4 * (1 + n) * n / 2 + n
= 4sum - 2n^2 - n
求和
sum2 = sub + sub2
= 8sum - 2n^2 - n
获得二元一次方程组
sum2 = 2sum + 2n^3 + n^2
sum2 = 8sum - 2n^2 - n
//转化成熟悉的数学形式就是
y = 2x + 2n^3 + n^2
y = 8x - 2n^2 - n
把一式代入二式或者二式子代入一式子得到结果
x = n(2n + 1)(n + 1) / 6
y = n(2n + 1)(4n + 1) / 3
推导结果
1^2 + 2^2 + 3^2 + 4^2 + ... + n^2 = n(2n + 1)(n + 1) / 6
对折推导
(n + 1)^2 + (n + 2)^2 + ... + (n + n)^2 = n(2n + 1)(7n + 1) / 6
通用推导
0< m < n , n - (m - 1) = k
m^2 + ... + n^2 = (n(2n + 1)(n + 1) - (m - 1)(2(m - 1) + 1)((m - 1) + 1)) / 6
= k(6n^2 + 6n -6kn + 2k^2 - 3k + 1) / 6 //此处省略简单繁琐的计算过程
= k((2n + 1)(3n + 1) + n - 1 - 6kn + (2k - 1)(k - 1)) / 6
= k((2n + 1)(3n + 1) + (1 - 6k)n + (2k - 1)(k - 1) - 1) / 6
注
对折推导中n个数是从n+1开始计算平方和的
网友评论