Google


Friday, September 26, 2008

Golden ratio

Here is a simple quick SAS program to calculate the golden ratio, after 70 steps it reaches 1.6180339885, which is pretty close to the true solution.

 

data phi;

phi1=1;

phi2=(phi1+1)/phi1;

incr=.1;

output;

do i=2 to 70;

    if phi1<phi2 then phi1+incr;

    else do;

        phi1+(-incr);

        incr=incr/10;

    end;

    phi2=(phi1+1)/phi1;

    output;

end;

run;

No comments: