Calculating the value of Phi aka the Golden Ratio in Perl

I was watching a video by 3blue1brown and decided to code up the Continued Fraction of “phi” aka “The Golden Ratio“. It’s pretty simple, it’s basically a recursive function (Here’s a link to the Mathematical Definition of a Recursion and the Programming Definition of Recursion) of 1 + 1/x. But you can code it in a loop. I did a quick Perl Script using an infinite loop. You first hit the golden ratio at 9 iterations, and at 11 iterations of the loop the value becomes metastable at a precision of 6. Here’s the script and output:

Perl Script to calculate Phi using the Continued Fraction (a function call in a loop here):

Standard Output paused at 21 iterations of the loop:

 

This entry was posted in Science. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.