Alan Posted December 12, 2013 Share Posted December 12, 2013 Given the first few terms of y = f(x), can you determine what the function f() is? x = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 y = 0, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2 I should point out that I don't know the answer, although I have written a generator which works perfectly, however I'm specifically looking for a single formula. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted December 12, 2013 Share Posted December 12, 2013 As it goes up and down it seems to be something related to a sin or cos. As the numbers are also int, I would say there is a rounding too as well as like a second sin to increase the effect over time. Remains to tweak all those to find the right effect. Other option use Mathlab and it's curve fitting to let it find it for you ;) Quote Link to comment Share on other sites More sharing options...
sniko Posted December 12, 2013 Share Posted December 12, 2013 Ah, I thought I was on to something, until I got to x=5. 1/sqrt(1+0^0) 2/sqrt(2+1^1) 3/sqrt(3+2^2) 4/sqrt(4+3^3) x / sqrt(x+(x-1)^(x-1)) Quote Link to comment Share on other sites More sharing options...
dnenb Posted December 12, 2013 Share Posted December 12, 2013 Do you know anything about the function? Does it take and produce only integers? As bertrand said you could easily use matlab or an equivalent package to fit a function to the data: [ATTACH=CONFIG]1233[/ATTACH] Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted December 13, 2013 Share Posted December 13, 2013 here is an approximation (a few values are not appearing at the right time but you can continue to tweak the formula): a=1.1 b=0.08 c=0.46 d=1 e=0.28 y=round(sin((x-c)/a+(e*x)))*(x*b)+d)) [ATTACH=CONFIG]1234[/ATTACH] Series 2 (and column C) are your original values, while column B and series 1 is my current approximation. Mathlab or excel can both help you ;) Quote Link to comment Share on other sites More sharing options...
Alan Posted December 14, 2013 Author Share Posted December 14, 2013 Some interesting suggestions, I hadn't considered trig functions. @denb; yes only integers are produced. For anyone who is curious: <?php $index = 1; $x = 0; $y = 0; $direction = 0; $matrix = array(array(1, 0), array(0, 1), array(-1, 0), array(0, -1)); for ($i = 0; $i < 10; $i++) /* increment 10 to suit */ { for ($j = 0; $j < floor(($i + 2) / 2); $j++) { echo sprintf("%d : ( %d , %d )\n", $index, $x, $y); $index++; $x += $matrix[$direction][0]; $y += $matrix[$direction][1]; } $direction = ++$direction % 4; } If you plot the generated coordinates; you end up with a rather remarkable and handy ""curve"". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.