Golden ratio/Convergence: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) m (→{{header|REXX}}: minor correction) |
Walterpachl (talk | contribs) (→{{header|ooRexx}}: added ooRexx code) |
||
Line 1,174: | Line 1,174: | ||
<pre>Result: 987/610 (1.618032786) after 14 iterations |
<pre>Result: 987/610 (1.618032786) after 14 iterations |
||
The error is approximately -0.000001202</pre> |
The error is approximately -0.000001202</pre> |
||
=={{header|ooRexx}}== |
|||
<syntaxhighlight lang="oorexx">/* REXX |
|||
* Compute the Golden Ratio using recursion |
|||
* 20230604 Walter Pachl |
|||
*/ |
|||
Numeric Digits 16 |
|||
Parse Value '1 1 1e-5' With oldPhi phi limit |
|||
Do iterations=1 By 1 Until delta<=limit |
|||
phi=1+1/oldPhi |
|||
delta=abs(phi-oldPhi) |
|||
If delta>limit Then |
|||
oldPhi=phi |
|||
End |
|||
actualPhi=(1+rxCalcsqrt(5,16))/2 |
|||
Say 'Final value of phi : ' phi |
|||
Say 'Actual value : ' actualPhi |
|||
Say 'Error (approx) :' (phi-actualPhi) |
|||
Say 'Number of iterations:' iterations |
|||
::REQUIRES RXMATH library |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Final value of phi : 1.618032786885246 |
|||
Actual value : 1.618033988749895 |
|||
Error (approx) : -0.000001201864649 |
|||
Number of iterations: 14 |
|||
</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |