# Find a sequence given the sums of its terms

For a certain sequence of numbers, the sum of the first $n$ numbers in the sequence is given by $n^3+4n$ for all positive integers $n$. What is the fifteenth number in the sequence?

How do you solve this problem the most efficient way?

• Are you sure you're on an appropriate site? This one is for Mathematica programming. Oct 9, 2015 at 4:10
• Step 1: Ask on the right fora. You're after math.stackexchange...
– ciao
Oct 9, 2015 at 4:10
• Ask how to solve it on a site full of people who like solving problems? :-) Oct 9, 2015 at 4:22
• People coming in from the hot questions list, please note the answers are fancy looking ways to do subtraction. I seriously don't understand the top answer (as in, why the duck that is the top answer), top answer should be s(15)-s(14) Oct 9, 2015 at 9:35
• @AlecTeal The reason why my fellow Mathematica(TM) programmers and scientists found my answer interesting is because it's a literal translation to Mathematica(TM) of the problem exactly as posed by the OP (Solve fizz when buzz happens), without thinking in the math involved, and showing that Mathematica (TM) is able to solve it without human "intervention" Oct 9, 2015 at 13:17

Solve[Table[Sum[f[i], {i, 1, n}] == n^3 + 4 n, {n, 15}], Array[f, 15]]

(*
{{f[1] -> 5, f[2] -> 11, f[3] -> 23, f[4] -> 41, f[5] -> 65,
f[6] -> 95, f[7] -> 131, f[8] -> 173, f[9] -> 221, f[10] -> 275,
f[11] -> 335, f[12] -> 401, f[13] -> 473, f[14] -> 551,
f[15] -> 635}}
*)

• "the most efficient way" is the one that takes you less time Oct 9, 2015 at 4:15
• I love this for not doing any analysis of the problem; just plugin what you know and have it solved. Oct 9, 2015 at 4:18
• @BrettChampion ha! That's why I wrote the comment above :) Oct 9, 2015 at 4:19
• My solutions were variants of Differences[Table[n^3 + 4 n, {n, 0, 15}]], but that requires a step of reasoning first. Oct 9, 2015 at 4:20
• @BrettChampion Thinking is cheating :) Oct 9, 2015 at 4:20
(FindSequenceFunction@ Differences[Prepend[n^3 + 4 n /. n -> Range@10, 0]])@15

(* 635 *)


Might as well...

DifferenceDelta[n^3 + 4 n, n] /. n -> 15 - 1

• That's the one function I always forget among the 848747 built-ins ;-} +1
– ciao
Oct 9, 2015 at 6:03
• Familiarity with the difference calculus has so far served me well. :) Oct 9, 2015 at 6:08

Let $S_n=\sum^n_{j=1}a_n$. So $a_n=S_n-S_{n-1}$.

5 - 3 n + 3 n^2 /. n -> 15


yields 635. (Mathematica can obviously do this).

• I saw the beginning of your answer and thought you were going to give an answer suitable for math.se. Oct 9, 2015 at 6:41
• @BrettChampion...I can delete if you feel this is not in the spirit of the site. I just thought given the precise expression of the question, this was the simplest approach... Oct 9, 2015 at 6:44
• This is more or less what DifferenceDelta[] does, made explicit. Oct 9, 2015 at 8:15
• @J. M. yes...I am sorry if it seemed like being a wise-guy...I just thought simplicity was warranted...I did upvote your answer as I was not aware of DifferenceDelta. I am happy to delete and acknowledge all the answers get to the same result. :) Oct 9, 2015 at 8:19
• No, I didn't take it like that! I was merely adding an explanatory note; at least, OP will need to think a little bit more for your solution. :) Oct 9, 2015 at 8:21