Message Boards Message Boards

3 Replies
4 Total Likes
View groups...
Share this post:

How to fit two lists with some approximation?

Hi everyone emoticon

I have two lists. First have numerical data and date like
and this is huge list (over 3400 rows).
Second is Fibonacci sequence
{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89}
How can I fit second list (Fibonacci) to second column in first list (to find similar value in Fibonacci periods of time)? I can have any reasonable approximation if I like. I've tried something with Fit and FindFit but I'm stuck.
3 Replies
Posted 11 years ago
You might find this function useful:
toSeconds[d_] :=
    ToExpression /@ {StringTake[#, 4], StringTake[#, {5, 6}],
      StringTake[#, {7, 8}]}] &[ToString[d]]
That will convert your timestamps to seconds since 1st January 1900; toSeconds[19000101]=0, toSeconds[20130725]=3583699200

Try running this code:
data = Table[{t, 2 + 3 Fibonacci[t] + RandomReal[]}, {t, 6}];
FindFit[data, a + b Fibonacci[c t], {a, b, c}, t]
Hopefully that can get you started-
POSTED BY: Matt Henderson
Now I change a little my idea, but steel doesn't work. Here's my code:
fibonacci = {{1, 1}, {2, 1}, {3, 2}, {4, 3}, {5, 5}, {6, 8}, {7, 13}}
fmatch = Fit[fibonacci, {1, x, x^2, x^3, x^4, x^5}, x]
matchdata = Fit[import, fmatch, x]
And then, when I want to see this matching, I see only ListPlot:
Show[ListPlot[import], Plot[matchdata, {x, 20100101, 20130810}]]
import is matrix of date and some values (like in first post).

I want fit Fibonacci sequence to my data, but only in part of it. Can Mathematica find best matching in only part of data (but automatically choose which part)?

Below I draw what I want 

Red dots - my data
Blue curve (or dots if it possible) - matching Fibonacci sequence by Mathematica (I drew it by hand) 

Second possibility of matching

Match Fibonacci sequence to my data when Fibonacci is period of time and values are similar (with any reasonable approximation). But in this case I have totally no idea how do that, so I want do first possibility now (but maybe this is easier, I don't know).
Hi, Marcin, welcome to Wolfram Community! Could you please post the code for your attempts of fitting? Then it'd be easier for us to understand what you need and where you got stuck. Thanks!
POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract