21 lines
533 B
Text
21 lines
533 B
Text
include "NSLog.incl"
|
|
|
|
void local fn Iterate
|
|
double oldPhi = 1.0, phi = 1.0, limit = 1e-5
|
|
int iters = 0
|
|
while (YES)
|
|
phi = 1.0 + 1.0 / oldPhi
|
|
iters++
|
|
if ( abs( phi - oldPhi ) <= limit ) then break
|
|
oldPhi = phi
|
|
wend
|
|
NSLog( @"Final value of phi: %16.14f", phi )
|
|
double actualPhi = ( 1.0 + fn sqrt(5.0) ) / 2.0
|
|
NSLog( @"Actual value of phi: %16.14f", actualPhi )
|
|
NSLog( @"Error (approx): %16.14f", phi - actualPhi )
|
|
NSLog( @"Number of iterations: %d", iters )
|
|
end fn
|
|
|
|
fn Iterate
|
|
|
|
HandleEvents
|