-2

Considering a sequence of integers, how can I find the polynomial function that models it? (i.e generates the first item for x=1, second items for x=2, etc)

For example, let us consider this sequence: 1, 683, 44287, 838861. How do I find that the matching generating function is y = 118008*x^3 - 686587*x^2 + (10^6)*x - 665807.

note: Code must work up to tenth degree.

user2705335
  • 357
  • 1
  • 3
  • 8
  • 2
    You question is not fitting the requirements for SO. In addition it's not the language that matters here, it's the algorithm. Finding generating functions is a problem that is not directly related to programming at all. – Jack Aug 28 '13 at 18:17
  • 4
    This question appears to be off-topic because it is about maths (try http://math.stackexchange.com). – Oliver Charlesworth Aug 28 '13 at 18:18
  • Why is it so? I am very well aware of solving this on paper, what I am asking is about the algorithm. – user2705335 Aug 28 '13 at 18:21
  • @user2705335: If you know how to solve it on paper, then you have an algorithm... – Oliver Charlesworth Aug 28 '13 at 20:48
  • This was found on Stack Overflow. Hopefully this will solve your problem. http://stackoverflow.com/questions/13435257/canonical-coefficients-from-newton-polynomial – Stephen McConnell Aug 28 '13 at 18:23
  • I can see your point, but it isn't that simple for me. What I would do on paper is find a,b,c,d of a*x^3 + b*x^2 + c*x + d by a series of 4 equations. How do you implement such thing to a computer? Maybe arrays? I don't know, and anyway I'm certain there is a much simpler way. – user2705335 Aug 28 '13 at 22:55

1 Answers1

1

This isn't really a java question... it's a basic math question. If you consider [1, 4, 9, 16, 25], take the differences between them, you get [3, 5, 7, 9]. Do that again and you get [2, 2, 2].

Now look at [1, 8, 27, 64, 125]... the differences there are [7, 19, 37, 61]. The differences of those work out to [12, 18, 24] and the differences yet again are [6, 6].

If you did it for x^4, then the fourth set of differences you'd have would be [24, 24, 24...] etc.

In other words, if the highest term in the equation is a*x^n, then the ultimate difference you get, after taking the difference n times, is a*n!.

So, starting with [1, 683, 44287, 838861] the first difference is [682, 43604, 794574], the second difference is [42922, 750970] and the third difference is [708048]. So divide that by 3! or 6 and you get the first term of 118008*x^3.

Now you get to go back, subtract 118008*x^3 from your original sequence, and figure out the x^2 term from your new sequence of [-118007, -943381, -3141929, -6713651]. There's probably a shortcut you can put in here so you don't have to go all the way back to the beginning, but that's up to you to figure out.

dcsohl
  • 7,186
  • 1
  • 26
  • 44