| Date Assigned: | Fri Oct-13 |
| Date Due: | Mon Oct-16 |
It is well known that the sum of the first N positive integers is N * (N+1) / 2. Thus,
1 + 2 + 3 + 4 + 5 = 5 * (5+1) / 2 = 5 * 3 = 15.It is less well known, but equally true, that the sum of the squares of the first N positive integers is (N * (N+1) * (2N+1))/6. Thus,
12 + 22 + 32 + 42 + 52 = (5 * (5+1) * (2*5+1)) / 6 = (5 * 6 * 11)/6 = 55.So, turns out (you can trust me on this one) that the sum of the first N positive integers raised to the k power is a (k+1) polynomial. So, you get:
1k + 2k + 3k + ... + Nk = ak+1Nk+1 + akNk + ak-1Nk-1 + ... + a1N1 + a0Let's express the two cases mentioned (k=1 and k=2) in this form:
k=1:
11 + 21 + 31 + ... + N1 = N * (N+1) / 2 = (1/2) N2 + (1/2) N1 + 0k=2:
Hence: a2 = 1/2, a1 = 1/2, a0 = 0
12 + 22 + 32 + ... + N2 = (N * (N+1) * (2N+1))/6 = (1/3) N3 + (1/2) N2 + (1/6) N1 + 0So far, so good. Now, to compute this polynomial for arbitrary k, note the following: To solve for the k+2 coefficients (ak+1 to a0), you need k+2 equations. But you can generate these using the first k+2 positive integers -- from N=1 to N=k+2. So, when N=1:
Hence: a3 = 1/3, a2 = 1/2, a1 = 1/6, a0 = 0
1k = ak+11k+1 + ak1k + ak-11k-1 + ... + a111 + a0 = ak+1 + ak + ak-1 + ... + a1 + a0So when N=2:
1k + 2k = ak+12k+1 + ak2k + ak-12k-1 + ... + a121 + a0Continue in this fashion until you have created k+2 equations in k+2 unknowns. Special optional note (this may be safely ignored, and you will still get the right answer): consider the case when N=0. Here, all the ai are eliminated except for a0, and we also conclude that a0 always equals 0 for any k. Thus, if you want, you can drop a0 from your equations and use k+1 equations (from N=1 to N=k+1) in the remaining k+1 unknowns.
NOW... You use your Gaussian Elimination code from a previous assignment to solve for these k+2 variables. Output the polynomial in as natural and readable a form as you can muster.
You may want to confirm this polynomial actually works with a few randomly chosen N as well.