# number pattern sequence tia sal2

Discussion in 'Recreational Math' started by sal2, Feb 7, 2008.

1. ### sal2Guest

number pattern sequence tia sal2

Greetings All

I'm having some trouble figuring out a sequence of numbers using common
Difference
I've figured out the polynomial for the even numbers for the sequence but
the odd numbers have a repeating pattern which I'm not sure how to create
a Polynomial for.

I've included my work here
http://demos.onewithall.net/number_patterns.jpg on the even numbers which
Iâ€™ve verified and they are correct.

I've included the odd numbers also I started doing the sequence of
numbers using common Difference but as you can see I get a pattern of
repeating numbers (-5,4).

How can I go about getting the polynomial for the odd numbers like I did
for the even ones.

Tia sal2

sal2, Feb 7, 2008

2. ### Daniel LichtblauGuest

I'm not sure what you did but your result is at least slightly off.

There are at least a couple of standard methods to interpolate a
polynomial from values. One is named for Lagrange, and is what gets
used inside Mathematica.

First note that you have nine points but only eight degrees of
freedom. So unless there is an algebraic dependency in the first eight
data points, they suffice to give a unique interpolating polynomial of
degree 7. We'll see this below.

datapairevens = {{2,3},{4,8},{6,4},{8,9},{10,5},{12,1},{14,6},{16,2}};

In:= InputForm[polyevens =
Expand[InterpolatingPolynomial[datapairevens, n]]]
Out//InputForm=
-308 + (101389*n)/280 - (5045*n^2)/32 + (2203*n^3)/64 -
(265*n^4)/64 + (89*n^5)/320 - (5*n^6)/512 + n^7/7168

Here I check that we recover the correct values, not just for the
first eight points but also the ninth.

In:= polyevens /. n->Range[2,18,2]
Out= {3, 8, 4, 9, 5, 1, 6, 2, 7}

For your odd x values it is a different story.

datapairodds = {{1,1},{3,6},{5,2},{7,7},{9,3},{11,8},{13,4},{15,9}};

In:= InputForm[polyodds =
Expand[InterpolatingPolynomial[datapairodds, n]]]
Out//InputForm=
-1047/8 + (543773*n)/2240 - (5899*n^2)/40 + (13657*n^3)/320 -
(53*n^4)/8 + (181*n^5)/320 - n^6/40 + n^7/2240

In:= polyodds /. n->Range[1,17,2]
Out= {1, 6, 2, 7, 3, 8, 4, 9, 581}

We crrectly recover the first eight, but not the ninth.

Daniel Lichtblau
Wolfram Research

Daniel Lichtblau, Feb 7, 2008

3. ### mensanatorGuest

No, they are not correct.

You based your polynomial on F(16)=2, but when you did your
check, you have F(18)=2.

F(18)=2 for the polynomial constructed, but the actual value
of F(16) for this polynomial is 1.375.

Your original sequence also has F(18)=7 but the polynomial
calculated gives F(18)=2.

The polynomial doesn't match the sequence.

Is the odd sequence supposed to be the same function as the
even sequence?

mensanator, Feb 7, 2008
4. ### sal2Guest

Thanks for finding my mistake...and I thought I was so careful double
checking everything...

Yes the odd sequence is suppose to be the same function as the even
sequence but I tried to split them up to see if that would be easier.
I'm trying to understand the process....

Math is very cool stuff sal2, Feb 7, 2008
5. ### sal2Guest

Thanks for the catch....I did the calculations again and updated the image

Yes the odd sequence is suppose to be the same function as the even
sequence but I tried to split them up to see if that would be easier.
I'm trying to understand the process....

sal2, Feb 7, 2008
6. ### sal2Guest

Thanks for the catch I fixed it...I had made sure I doubled checked
everything and of course I typed in a 18 instead of a 16 for one of the
numbers of f(n) and I did a copy paste (and I copied the error right into
the answer checking procedure hahahahah) the best laid plains Thanks I'll give it a try

aloha

sal2, Feb 7, 2008
7. ### mensanatorGuest

I wouldn't think it would be easier. And what if the two
polynomials ended up being different?
I've got a program that uses Newton's Forward Differences Method.

But it requires that the first sequence number be F(0),
so, just for laughs, I put in your sequence assuming
the first element was F(0)

Seq: [1, 3, 6, 8, 2, 4, 7, 9, 3, 5, 8, 1, 4, 6, 9, 2, 5, 7]

To use NFDM, I need the first element from each row
of differences (along with the first sequence element).

Term0: [1, 2, 1, -2, -5, 28, -74, 148, -260, 448, -824, 1639, -3332,
6466, -11348, 16954, -18464, 2080]

The differences never became a constant, but it calculated
a polynomial anyway that does, in fact, reproduce the exact
input sequence

Polynomial n Original Sequence
----------- --- --------------
1 0 1
3 1 3
6 2 6
8 3 8
2 4 2
4 5 4
7 6 7
9 7 9
3 8 3
5 9 5
8 10 8
1 11 1
4 12 4
6 13 6
9 14 9
2 15 2
5 16 5
7 17 7

The Polynomial:

1
------------ * n**17
171003571200

-1097
------------ * n**16
653837184000

36739
------------ * n**15
217945728000

-1201891
------------ * n**14
130767436800

1990123
---------- * n**13
6227020800

-55134179
---------- * n**12
7185024000

607809893
---------- * n**11
4572288000

-1557627607
----------- * n**10
914457600

622897801
--------- * n**9
38102400

-269612052571
------------- * n**8
2286144000

13611333301
----------- * n**7
21384000

-9113459657
----------- * n**6
3592512

286432687397
------------ * n**5
39293100

-12359751904781
--------------- * n**4
851350500

1329935495788
------------- * n**3
70945875

-65550414896
------------ * n**2
4729725

1210487791
---------- * n**1
278460

1
- * n**0
1

So, the next term (n=18) would be

Polynomial n Original Sequence
----------- --- --------------
-65526 18 None

mensanator, Feb 7, 2008
8. ### sal2Guest

couple of others at school. But I might be willing to purchase another
one.

Thanks I'll give it a try

sal2, Feb 9, 2008
9. ### mensanatorGuest

One I wrote myself.
Well, I just went to Mathworld and implemented the
algorithm of NFDM. You could probably do the same
in Maple.

The program _I_ wrote is in Python. You might check
to see if you have that at your school. If not, it
doesn't cost anything and is certainly worth learning.

If you go that route, make sure you Google for "gmpy"
(I don't have their address handy), the Python version
of the GNU MultiPrecision library, as it isn't included
in the Python distribution. Just make sure you get
matching versions, Python 2.5.1 requires the version
of gmpy for 2.5.

Sometime this weekend I'll put the source code for
my polynomial program on my web-site and post a link
here.

mensanator, Feb 9, 2008
10. ### sal2Guest

Yes we have it...
will do
Thanks

sal2, Feb 9, 2008
11. ### mensanatorGuest

You'll find it here:

http://members.aol.com/mensanator/polynomial.py

algorithm and many worked out examples, including
yours (triggers a warning, but finds the polynomial
anyway).

mensanator, Feb 9, 2008
12. ### sal2Guest

Thanks so much I'll give it a try sal2, Feb 10, 2008
13. ### mensanatorGuest

One more thing. Your original sequence crahed my program and
the code I posted had a hasty attempt at fixing it - an attempt
that worked for your example but won't work generally.

But it's easy to fix:

Change
#
# Duh, product must be 0, not sum (may have both pos and neg
diffs)
#
p = temp
for pp in temp[1:]:
p *= pp #<-- change this
if p==0:
done = True

to
#
# Duh, product must be 0, not sum (may have both pos and neg
diffs)
#
p = temp
for pp in temp[1:]:
p |= pp #<-- to this
if p==0:
done = True

mensanator, Feb 11, 2008
14. ### sal2Guest

ok I'll update it and make the change

sal2, Feb 12, 2008