20 lines
374 B
Text
20 lines
374 B
Text
var iter = integer
|
|
var phi, phi0, diff, golden = real
|
|
|
|
phi0 = 1
|
|
iter = 0
|
|
repeat
|
|
begin
|
|
phi = 1 + (1 / phi0)
|
|
diff = abs(phi - phi0)
|
|
phi0 = phi
|
|
iter = iter + 1
|
|
end
|
|
until diff < 1E-5
|
|
|
|
print "Value ="; phi; " after"; iter; " iterations"
|
|
rem - compare with value derived from formula
|
|
golden = 0.5 * (1 + sqr(5))
|
|
print "Approximate error = "; phi - golden
|
|
|
|
end
|