|
Fibonacci numbers, Golden ratio
|
|
08-16-2010, 03:09 AM
(This post was last modified: 08-26-2010 03:20 AM by drdebcol.)
Post: #1
|
|||
|
|||
|
Fibonacci numbers, Golden ratio
You already know about Fibonacci sequence. Each number of Fibonacci sequence is the sum of the previous two numbers, starting with 0 and 1.
About Fibs you have at Wikipedia : http://en.wikipedia.org/wiki/Fibonacci_numbers The sequence begins : Code: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610 and so on.The higher up in the sequence, the closer two consecutive Fibonacci numbers of the sequence divided by each other will approach the "golden ratio" (approximately 1 : 1.618 or 0.618 : 1). The golden ratio was used widely in the Renaissance in paintings. Famous Renaissance painters were painting things depending on this ratio. About "golden ratio" you have here : http://en.wikipedia.org/wiki/Golden_ratio Code: a(n+1)/a(n) = 1.618EPS is accuracy and it is difference between two iterations : Code: a(n+2)/a(n+1)-a(n+1)/a(n)>EPSCode: #define EPS 0.0001So here is the code in C : Code: #include <stdio.h>There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
08-16-2010, 06:58 AM
Post: #2
|
|||
|
|||
|
RE: Fibonacci numbers, Golden ratio
A bit above my head..but i get the general idea. Thanks for the contribution.
"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
08-16-2010, 08:46 AM
(This post was last modified: 08-16-2010 08:47 AM by drdebcol.)
Post: #3
|
|||
|
|||
RE: Fibonacci numbers, Golden ratio
(08-16-2010 06:58 AM)Back_track Wrote: A bit above my head..but i get the general idea. Thanks for the contribution.Well there is a bit of maths in this. Some knowledge about Calculus can help in understanding this task. Though, when you look at it from a programmers point of view, it is just a do . . while loop. There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
08-16-2010, 10:28 AM
Post: #4
|
|||
|
|||
|
RE: Fibonacci numbers, Golden ratio
Yeah, I understood the programs flow. It was just I don't have any calc. knowledge.
"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
08-26-2010, 03:18 AM
(This post was last modified: 08-26-2010 03:21 AM by drdebcol.)
Post: #5
|
|||
|
|||
|
RE: Fibonacci numbers, Golden ratio
After doing some research i have found better way to calculate Golden ratio, and that is not by using Fibonacci numbers, it is "Newton's method" known as "Newton's iteration" which i used for computing square roots here :
http://www.pro9ramming.com/square-root-c...-1159.html More about Newton's method you have on Wikipedia : http://en.wikipedia.org/wiki/Newton%27s_method Now let's see how this method works. Golden ratio (=1,61803 etc.) is the largest root of this polynomial : ![]() When we include this into Newton's method, it should look like : ![]() As you can see there are derivatives, so don't try to understand this without knowledge of calculus. Now when we have x(k+1), we need x(0) which is in this case 1. That is enough to calculate golden ratio depending on certain EPS which is in our case : Code: EPS = 0.0001Now i'll live demonstrate why this method has faster convergence (bigger speed) than Fibonacci numbers method explained above. First i'll post a bit modified code for Fibonacci numbers method : Code: #include <stdio.h>you'll get this (form - iteration = calc_on_that_iteration): ![]() As you can see, calculation of Golden ratio on 4 decimals (=1.6180) took 12 iterations (3rd decimal on 10th iteration). And now Newton's method code : Code: #include <stdio.h>![]() As you can see, 4th decimal is reached at 4th iteration (3rd decimal too). After running tests on more decimals, Newton's method proved that it is faster (has smaller complexity). To sum up, Fibonacci number method is interesting because of relation to Number theory, and it is accurate, but slow. Newton's method proved in this case (and in many cases not concerning this), that it is really fast and that it can calculate golden ratio in small number of iterations (depending on how much decimals you want). There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
« Next Oldest | Next Newest »
|






![[Image: 77027_goldenratioequation.png]](http://myph.us/pics/77027_goldenratioequation.png)
![[Image: 77028_goldenratioequation2.png]](http://myph.us/pics/77028_goldenratioequation2.png)
![[Image: 77033_goldenratiofibsmethod.jpg]](http://myph.us/pics/77033_goldenratiofibsmethod.jpg)
![[Image: 77034_goldenrationewtonsmethod.jpg]](http://myph.us/pics/77034_goldenrationewtonsmethod.jpg)