Group Abstract Group Abstract

Message Boards Message Boards

0
|
11.4K Views
|
17 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Create a function that replicates this series?

Posted 9 years ago

Hi All,

I am trying to create a function in Mathematica that replicates the following series of numbers.

data = {1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703, 813}

Length[data] = 15

So I would have a functionData[[15]] = 813

From this functionData[x] I would be able to find any value within this series along the positive integer domain from 1 to infinity.

functionData[ integer domain from 1 to infinity ]

I can replicate this series by creating columns lists within Microsoft Excel spreadsheet & adding corresponding elements in rows to create this series. But I have been having problems doing something similar in Mathematica. My initial approach shown below. This is unfinished & maybe the wrong approach.

In[5]:= plus7 = Table[i*7, {i, 2, 10}]

Out[5]= {14, 21, 28, 35, 42, 49, 56, 63, 70}

In[7]:= PadLeft[plus7, 11]

Out[7]= {0, 0, 14, 21, 28, 35, 42, 49, 56, 63, 70}

In[8]:= PadRight[{1, 7}, 11]

Out[8]= {1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0}

In[9]:= PadRight[{1, 7}, 11] + PadLeft[plus7, 11]

Out[9]= {1, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70}

I would be very grateful for your advice & assistance. Many thanks for your help & attention.

Best regards, Lea...

POSTED BY: Lea Rebanks
17 Replies
Posted 9 years ago

Many thanks Martin again. Really Excellent.

POSTED BY: Lea Rebanks

Hi Lea

Even shorter:

Clear[c]

c[1] = 1;
c[2] = 7;

c[n_] := c[n] = 8 + 2 c[n - 1] - c[n - 2]

Table[c[k], {k, 1, 15}]
POSTED BY: Martin Bittcher
Posted 9 years ago

What Weil Aerts showed you is the "proper way" to go about looking for such a formula (graphing data and using one's experience about recognizing functions). However, an alternative that I just recently saw at Mathematica StackExchange is a "lazy person's way" (or "efficient person's way") which consists of going to https://oeis.org/ and typing in the sequence of numbers.

Typing you your sequence results in a(n) = 4n^2 - 6n + 3.

POSTED BY: Jim Baldwin

Disagree; NonlinearModelFit does not look for a formula, it will find you the coefficients once you give it a formula! FindSequenceFunction is the proper, which is specifically designed for sequences. ((non)linearmodelfit is designed for data with any step, and 99% of the time used for cases where there is no exact fit; i.e. to find the best fit).

POSTED BY: Sander Huisman
Posted 9 years ago

Many thanks Jim. Really Excellent.

POSTED BY: Lea Rebanks

Hi Lea Did you think of "functions that remember their values"? Then a[k] might be your choice.:

b[1] = 1;

b[2] = 7;

b[3] = 14;

b[n_] := b[n] = b[n - 1] + 8

a[1] = 1;

a[2] = 7;

a[n_] := a[n] = a[n - 1] + b[n]

POSTED BY: Martin Bittcher
Posted 9 years ago

Many thanks Martin. Really Excellent.

POSTED BY: Lea Rebanks

Create a function that replicates this series?

POSTED BY: Martin Bittcher
Posted 9 years ago

Hello Lea,

I analyzed your data in the following way: first make a graph (ListPlot): this looks like a second degree. Apply NonLinearModelFit with a quadratic equation. Inspect the residues. So the function is known. Use this function in a definition (series). Reproduce your series. And just another number (sort of infinity).

Good Luck, Wiel

data = {1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703,
    813};

model = NonlinearModelFit[data, {a x^2 + b x + c}, {a, b, c}, x];
model["BestFitParameters"]
{a -> 3.999999999999997`, b -> -5.999999999999966`, 
 c -> 2.9999999999998295`}

model["FitResiduals"]

{1.3988810110276972`*^-13, 1.1546319456101628`*^-13, \
9.947598300641403`*^-14, 8.526512829121202`*^-14, \
7.105427357601002`*^-14, 8.526512829121202`*^-14, \
8.526512829121202`*^-14, 1.1368683772161603`*^-13, \
1.1368683772161603`*^-13, 1.1368683772161603`*^-13, \
2.2737367544323206`*^-13, 2.2737367544323206`*^-13, \
3.410605131648481`*^-13, 2.2737367544323206`*^-13, \
3.410605131648481`*^-13}

series[n_] := 3 - 6 n + 4 n^2

Table[series[k], {k, 1, 15}]
{1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703, 813}

series[1000]
3994003
POSTED BY: Wiel Aerts
Posted 9 years ago

Very nice coding. Excellent. This method seems to do the trick & is accurate at the 1000th integer.

Many thanks. Lea...

POSTED BY: Lea Rebanks

Of course it would be accurate,fits is perfect. My solution is exact, will work for any integer, billion, trillion, google... . Moreover I gave you all the constant components, all the linear components and quadratic et cetera. What do you want more?

POSTED BY: Sander Huisman
Posted 9 years ago

Given that we have now found the function for the series

data = {1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703, 813}
series[n_]:=3-6 n+4 n^2

If I create 2 different series as multiplications of this series - for example:-

series1[n_]:= (3-6 n+4 n^2) * 30
series2[n_]:= (3-6 n+4 n^2) * 47

I tried using

Intersection[ series1 , series2 ] 

with a million elements & found nothing.

Question - Is there one or more common values between series1 & series2 within the Integer domain from 1 to infinity?

Please could someone check & confirm whether any values are shared or not.

Many thanks for your help & attention. Lea...

POSTED BY: Lea Rebanks

It can be done like this:

seq = {1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703, 813};
seqlen = Length[seq];
prefactors = CoefficientList[FindSequenceFunction[seq][x], x];
powers = Range[Length[prefactors]] - 1;
values = MapThread[#2 Range[seqlen]^#1 &, {powers, prefactors}];
values
Total[values]

{
    {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
    {-6,-12,-18,-24,-30,-36,-42,-48,-54,-60,-66,-72,-78,-84,-90},
    {4,16,36,64,100,144,196,256,324,400,484,576,676,784,900}
}

{1,7,21,43,73,111,157,211,273,343,421,507,601,703,813}
POSTED BY: Sander Huisman
Posted 9 years ago

Many thanks for your help Sander.

I see from your coding that the FindSequenceFunction[seq] gives

3 - 6 #1 + 4 #1^2 &

Which is the function I am after.. Many thanks for your help & attention. Lea...

POSTED BY: Lea Rebanks
Posted 9 years ago

Given that we have now found the function for the series

data = {1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703, 813}
series[n_]:=3-6 n+4 n^2

If I create 2 different series as multiplications of this series - for example:-

series1[n_]:= (3-6 n+4 n^2) * 30
series2[n_]:= (3-6 n+4 n^2) * 47

I tried using

Intersection[ series1 , series2 ] 

with a million elements & found nothing.

Question - Is there one or more common values between series1 & series2 within the Integer domain from 1 to infinity?

Please could someone check & confirm whether any values are shared or not.

Many thanks for your help & attention. Lea...

POSTED BY: Lea Rebanks
Posted 9 years ago

Hi Bill,

Many thanks for the suggestion. But this is not the type of solution I am looking for.

I am looking for an approach by re-engineering the elements in this series by combining the vectors or arrays that make up this series progression. I can do this in Excel, but I am still struggling to effectively achieve this in Mathematica.

Do you have any other suggestions.

Many thanks for your help & attention, Lea...

POSTED BY: Lea Rebanks
Posted 9 years ago

Usually I start by graphing the available data.

data = {1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703, 813};
ListPlot[data]

Hummm. Looks roughly like a parabola, but that is only a first guess.

Hint: Look at the documentation for Fit and see if that might let you find something interesting and useful.

That might be enough if you work quickly before someone blurts out the answer and spoils the learning opportunity.

POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard