3

If I am given the numbers [1,2,1] and I want to find the sum of each number with it's adjacent neighbors (in a ring) repeated a number of times. I can use the following formula:

base case: [x=1, y=2, z=1]
repeat 7 times.
staring with index 0 or (variable x):
round 1 index 0: [(x+y+z), y, z] == [4, 2, 1]
round 2 index 1: [(x+y+z), (x+2y+2z), z] == [4, 7, 1]
round 3 index 2: [(x+y+z), (x+2y+2z), (2x+3y+4z)] == [4, 7, 12]
round 4 index 0: [(4x+6y+7z), (x+2y+2z), (2x+3y+4z)] == [23, 7, 12]
round 5 index 1: [(4x+6y+7z), (7x+11y+13z), (2x+3y+4z)] == [23, 42, 12]
round 6 index 2: [(4x+6y+7z), (7x+11y+13z), (13x+20y+24z)] == [23, 42, 77]
round 7 index 0: [(24x+37y+24z), (7x+11y+13z), (13x+20y+24z)] == [142, 42, 77]

Since the sequence can be repeated millions of times, I am wondering how I can calculate the i-th round without calculating rounds 0 through i. Any advice would be appreciated.

Justin
  • 4,196
  • 4
  • 24
  • 48
  • Interesting! It seems like some kind of generalization for fibonacci, since if you use `base=[1,1]` - you get fibonacci series. It [fibonacci] has a [close formula](http://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_expression), maybe using the same tools one could derive a formula for this one as well. Anyway, you will probably have better chance for an answer in [math.SE](http://math.stackexchange.com/) – amit Mar 05 '12 at 21:47
  • 2
    Interesting question, but probably belongs on [math.se] – Jim Garrison Mar 05 '12 at 22:07

1 Answers1

4

This question should be migrated to math.stackexchange.com, but:

If we call X[n] the column vector (x[n],y[n],z[n]) were the "n", the "time" index means a full round, we get the relation X(n+1) = A X(n) where A is the matrix

       1  1  1
  A =  1  2  2
       2  3  4

and hence X(n) = A^n X(0)

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • Damn I was just about to post this same thing! +1 – BlueRaja - Danny Pflughoeft Mar 05 '12 at 22:20
  • Man. Good job! Just wondering, how did you know that? Is it a known problem in number theory or something along those lines? – Justin Mar 05 '12 at 22:30
  • @Justin: I don't know how leonbloy did it, but I just considered three of your "rounds" as one "step," and tried to figure out how x, y, and z changed in relation to each other each step. It turns out that x, y, and z all change as linear functions of x, y, and z, which immediately suggests that you can just represent the change as a matrix. – BlueRaja - Danny Pflughoeft Mar 05 '12 at 22:53
  • yes, that's pretty standard for any linear recursion – leonbloy Mar 05 '12 at 23:04
  • I looked at it for a couple hours today and never "figured out" the recurrence. I knew it must exist, just couldn't find it. Thanks again! – Justin Mar 05 '12 at 23:08