Golden ratio/Convergence: Difference between revisions

Added Applesoft, GW-BASIC, Minimal BASIC, MSX Basic, PureBasic, QBasic, Quite BASIC and True BASIC
(Added Ada)
(Added Applesoft, GW-BASIC, Minimal BASIC, MSX Basic, PureBasic, QBasic, Quite BASIC and True BASIC)
Line 193:
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Bas}}===
{{trans|C}}
Line 366 ⟶ 369:
Result: 1,6180327869 after 14 iterations
The error is approximately -0,0000012019</pre>
 
==={{header|GW-BASIC}}===
{{works with|Applesoft BASIC}}
{{works with|Chipmunk Basic}}
{{works with|PC-BASIC|any}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
{{works with|MSX BASIC|any}}
{{trans|BASIC256}}
<syntaxhighlight lang="qbasic">100 CLS : rem 100 HOME for Applesoft BASIC : DELETE for Minimal BASIC
110 LET I = 0
120 LET P0 = 1
130 LET P1 = 1+(1/P0)
140 LET D = ABS(P1-P0)
150 LET P0 = P1
160 LET I = I+1
170 IF .00001 < D THEN 130
180 PRINT "Result: ";P1;" after ";I;" iterations"
190 PRINT "The error is approximately ";P1-(.5*(1+SQR(5)))
200 END</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">Procedure using_Float()
Define iter.i = 0
Define.f phi0 = 1.0, phi1, diff
Repeat
phi1 = 1.0 + (1.0 / phi0)
diff = Abs(phi1 - phi0)
phi0 = phi1
iter + 1
Until (1.0e-5 > diff)
PrintN("Using type Float --")
PrintN("Result: " + FormatNumber((phi1), 10) + " after " + Str(iter) + " iterations")
PrintN("The error is approximately " + FormatNumber((phi1 - (0.5 * (1.0 + Sqr(5.0)))), 10))
EndProcedure
 
Procedure using_Double()
Define iter.i = 0
Define.d phi0 = 1.0, phi1, diff
Repeat
phi1 = 1.0 + (1.0 / phi0)
diff = Abs(phi1 - phi0)
phi0 = phi1
iter + 1
Until (1.0e-5 > diff)
PrintN("Using type Double --")
PrintN("Result: " + FormatNumber((phi1), 10) + " after " + Str(iter) + " iterations")
PrintN("The error is approximately " + FormatNumber((phi1 - (0.5 * (1.0 + Sqr(5.0)))), 10))
EndProcedure
 
OpenConsole()
using_Float()
PrintN("")
using_Double()
Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Using type Float --
Result: 1.6180328131 after 14 iterations
The error is approximately -0.0000011757
 
Using type Double --
Result: 1.6180327869 after 14 iterations
The error is approximately -0.0000012019</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{trans|BASIC256}}
<syntaxhighlight lang="qbasic">SUB iterate
iter = 0
phi0 = 1!
DO
phi1 = 1! + (1! / phi0)
diff = ABS(phi1 - phi0)
phi0 = phi1
iter = iter + 1
LOOP UNTIL (.00001 > diff)
 
PRINT "Result: "; phi1; " after "; iter; " iterations"
PRINT "The error is approximately "; phi1 - (.5 * (1! + SQR(5!)))
END SUB
 
CALL iterate
END</syntaxhighlight>
{{out}}
<pre>Result: 1.618033 after 14 iterations
The error is approximately -1.175678E-06</pre>
 
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|True BASIC}}===
{{trans|QBasic}}
<syntaxhighlight lang="qbasic">SUB iterate
LET iter = 0
LET phi0 = 1
DO
LET phi1 = 1+(1/phi0)
LET diff = abs(phi1-phi0)
LET phi0 = phi1
LET iter = iter+1
LOOP until (.00001 > diff)
PRINT "Result: "; phi1; " after "; iter; " iterations"
PRINT "The error is approximately "; phi1-(.5*(1+sqr(5)))
END SUB
 
CALL iterate
END</syntaxhighlight>
 
==={{header|Yabasic}}===
2,122

edits