I’m new to Mathematica and on WolframAlpha when you input a short number sequence you’ll usually get a nice differences tree, showing the differences of each level of differences. I was wondering how to get this same multi-level tree of the differences in longer numerical sequences on Mathematica? (instead of just one level at a time)
I was not able to figure out what you did in Wolfram|Alpha (a specific example is always helpful). Possibly this will give a start along the lines of what you want.
aa = {1, 81, 28, 13, 19, 57, 25, 87, 19, 44};
NestList[Differences, aa, 3]
(* {{1, 81, 28, 13, 19, 57, 25, 87, 19, 44}, {80, -53, -15, 6, 38, -32,
62, -68, 25}, {-133, 38, 21, 32, -70, 94, -130, 93}, {171, -17,
11, -102, 164, -224, 223}} *)
This variant will go all the way to the root, so to speak.
Most[FixedPointList[Differences, aa]]
(* Out[37]= {{1, 81, 28, 13, 19, 57, 25, 87, 19, 44}, {80, -53, -15, 6,
38, -32, 62, -68, 25}, {-133, 38, 21, 32, -70, 94, -130,
93}, {171, -17, 11, -102, 164, -224, 223}, {-188, 28, -113,
266, -388, 447}, {216, -141, 379, -654, 835}, {-357, 520, -1033,
1489}, {877, -1553, 2522}, {-2430, 4075}, {6505}, {}} *)
Wow, thanks! Appreciate it. That is what I wanted essentially. Although now I’d like to figure out a way to make it look like this, if possible? This is how it appears in WolframAlpha:
WolframAlpha–1_2_3_4_10_19_36_69_134–2014-12-03_1110.bmp (366 KB)
Does anyone know how to produce a differences to multiple levels (like the above example from WolframAlpha) on Mathematica?
I can sort of produce it, but not in the elegant way it looks above…
That looks awesome, almost perfect, except that I want the original sequence to appear as the first line… how do I do that?
(obviously completely new to Mathematica)
Still though, when I copied it to try it, I got this result:
SetDelayed::write: Tag Times in Null xypos[xs_List,y_] is Protected.
It didn’t come out.
If i copy the above it works fine, clear your Memory (or restart mathematica) to be sure…
here is it with the original sequence:
ClearAll[xypos]
xypos[xs_List, y_] := MapThread[Text[#2, {#1, y}] &, {2 Range[Length[xs]] - Length[xs], xs}]
seq = {1, 2, 3, 4, 10, 19, 36, 69, 134};
seqs = Differences[seq, #] & /@ Range[0, Length[seq] - 1];
heights = Range[Length[seqs], 1, -1];
Graphics[MapThread[xypos, {seqs, heights}]]
Still not working for me, although I’m trying it with Mathematica Online… don’t know if that would make a difference,
but when I get home tonight I’ll try it then and see.
Looks great when you did it!
You’re right, it works fine on Mathematica… thanks, I really appreciate it, it’s awesome!
Is there a way though, to make it so that the actual sequence itself appears as the first line in the Output?
Copy my second code.
Sorry, didn’t realize that.
Thanks, Sander, I really appreciate your help.
Have a great holiday!
