...

/

Discussion: More Math, but Fun This Time

Discussion: More Math, but Fun This Time

Execute the code to understand the output and gain insights into recursive approximation.

Run the code

Now, it's time to execute the code and observe the output.

Press + to interact
#include <stdio.h>
double phi(double p, int precision)
{
while(precision)
return( p + 1/phi(p, precision-1) );
return(p);
}
int main()
{
double gr;
gr = phi(1.0, 15);
printf("Phi is %f\n", gr);
return(0);
}

Understanding the output

The code outputs the following line:

Phi is 1.618034
Code output

This is the golden ratio, represented by Greek letter phi, ϕϕ.

Golden ratio

The golden ratio is yet another of those mathematical joys that, like the Fibonacci sequence, appear frequently in nature. It’s important enough to have its own Greek letter assigned, phi or ϕϕ.

Phi

Phi is a concept that’s best illustrated as opposed to being explained in text. The diagram below illustrates how the ratio applies to two lengths, A and B.

Press + to interact
The ratio applied to lengths A and B
The ratio applied to lengths A and B

In this diagram, ϕϕ is the ratio of line ...