% GOLDMEAN an m-file to run through the recursive relationship % between the n-1, n and n+1 powers of the "Golden Mean". % % Initialize some variables Plast=1; Pnow=(sqrt(5)-1)/2; % Create some arrays and "place-holders" Pr=zeros(1,21); power=0:50; % Execute, in vectorized form, "the hard way" P=Pnow.^power; % Now use the recursive algorithm in a for loop Pr(1)=Plast; Pr(2)=Pnow; for i=3:51 Pr(i)=Plast-Pnow; Plast=Pnow; Pnow=Pr(i); end % Calculate their differences Pe=(P-Pr)./P; % Change the display format to "long" format long % Put it together and display on the screen as a table R=[power' P' Pr' Pe'] format short