Metallic ratios: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added code when showing an EXACT value.)
Line 694: Line 694:
numeric digits digs + length(.) /*specify number of decimal digs to use*/
numeric digits digs + length(.) /*specify number of decimal digs to use*/
metals= 'platinum golden silver bronze copper nickel aluminum iron tin lead'
metals= 'platinum golden silver bronze copper nickel aluminum iron tin lead'
@decDigs= ' decimal digits past the decimal point:' /*a literal used in SAY.*/
approx= 'the approximate value reached after ' /*literals that are used for SAYs. */
!.= /*the default name for a metallic ratio*/
!.= /*the default name for a metallic ratio*/
do k=0 to 9; !.k= word(metals, k+1) /*assign the (ten) metallic ratio names*/
do k=0 to 9; !.k= word(metals, k+1) /*assign the (ten) metallic ratio names*/
Line 713: Line 713:
if n>0 then do; say 'the first ' n " elements are:"; say $
if n>0 then do; say 'the first ' n " elements are:"; say $
end /*if N is positive, then show N nums.*/
end /*if N is positive, then show N nums.*/
@approx= 'approximate' /*literal (1 word) that is used for SAY*/
say approx #-1 ' iterations with ' digs " decimal digits past the decimal point:"
say format(r,,digs); say /*display the ration plus a blank line.*/
r= format(r,,digs) /*limit decimal digits for R to digs.*/
if datatype(r, 'W') then do; r= r/1; @approx= "exact"; end
say 'the' @approx "value reached after" #-1 " iterations with " digs @DecDigs
say r; say /*display the ration plus a blank line.*/
end /*m*/ /*stick a fork in it, we're all done. */</lang>
end /*m*/ /*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
Line 723: Line 726:
the first 15 elements are:
the first 15 elements are:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
the approximate value reached after 2 iterations with 32 decimal digits past the decimal point:
the exact value reached after 2 iterations with 32 decimal digits past the decimal point:
1
1.00000000000000000000000000000000


══════════════════════════ Lucas sequence for the golden ratio, where B is 1 ═══════════════════════════
══════════════════════════ Lucas sequence for the golden ratio, where B is 1 ═══════════════════════════
the first 15 elements are:
the first 15 elements are:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
the approximate value reached after 78 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 78 iterations with 32 decimal digits past the decimal point:
1.61803398874989484820458683436564
1.61803398874989484820458683436564


Line 735: Line 738:
the first 15 elements are:
the first 15 elements are:
1 1 3 7 17 41 99 239 577 1393 3363 8119 19601 47321 114243
1 1 3 7 17 41 99 239 577 1393 3363 8119 19601 47321 114243
the approximate value reached after 44 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 44 iterations with 32 decimal digits past the decimal point:
2.41421356237309504880168872420970
2.41421356237309504880168872420970


Line 741: Line 744:
the first 15 elements are:
the first 15 elements are:
1 1 4 13 43 142 469 1549 5116 16897 55807 184318 608761 2010601 6640564
1 1 4 13 43 142 469 1549 5116 16897 55807 184318 608761 2010601 6640564
the approximate value reached after 34 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 34 iterations with 32 decimal digits past the decimal point:
3.30277563773199464655961063373525
3.30277563773199464655961063373525


Line 747: Line 750:
the first 15 elements are:
the first 15 elements are:
1 1 5 21 89 377 1597 6765 28657 121393 514229 2178309 9227465 39088169 165580141
1 1 5 21 89 377 1597 6765 28657 121393 514229 2178309 9227465 39088169 165580141
the approximate value reached after 28 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 28 iterations with 32 decimal digits past the decimal point:
4.23606797749978969640917366873128
4.23606797749978969640917366873128


Line 753: Line 756:
the first 15 elements are:
the first 15 elements are:
1 1 6 31 161 836 4341 22541 117046 607771 3155901 16387276 85092281 441848681 2294335686
1 1 6 31 161 836 4341 22541 117046 607771 3155901 16387276 85092281 441848681 2294335686
the approximate value reached after 25 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 25 iterations with 32 decimal digits past the decimal point:
5.19258240356725201562535524577016
5.19258240356725201562535524577016


Line 759: Line 762:
the first 15 elements are:
the first 15 elements are:
1 1 7 43 265 1633 10063 62011 382129 2354785 14510839 89419819 551029753 3395598337 20924619775
1 1 7 43 265 1633 10063 62011 382129 2354785 14510839 89419819 551029753 3395598337 20924619775
the approximate value reached after 23 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 23 iterations with 32 decimal digits past the decimal point:
6.16227766016837933199889354443272
6.16227766016837933199889354443272


Line 765: Line 768:
the first 15 elements are:
the first 15 elements are:
1 1 8 57 407 2906 20749 148149 1057792 7552693 53926643 385039194 2749201001 19629446201 140155324408
1 1 8 57 407 2906 20749 148149 1057792 7552693 53926643 385039194 2749201001 19629446201 140155324408
the approximate value reached after 22 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 22 iterations with 32 decimal digits past the decimal point:
7.14005494464025913554865124576352
7.14005494464025913554865124576352


Line 771: Line 774:
the first 15 elements are:
the first 15 elements are:
1 1 9 73 593 4817 39129 317849 2581921 20973217 170367657 1383914473 11241683441 91317382001 741780739449
1 1 9 73 593 4817 39129 317849 2581921 20973217 170367657 1383914473 11241683441 91317382001 741780739449
the approximate value reached after 20 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 20 iterations with 32 decimal digits past the decimal point:
8.12310562561766054982140985597408
8.12310562561766054982140985597408


Line 777: Line 780:
the first 15 elements are:
the first 15 elements are:
1 1 10 91 829 7552 68797 626725 5709322 52010623 473804929 4316254984 39320099785 358197153049 3263094477226
1 1 10 91 829 7552 68797 626725 5709322 52010623 473804929 4316254984 39320099785 358197153049 3263094477226
the approximate value reached after 20 iterations with 32 decimal digits past the decimal point:
the approximate value reached after 20 iterations with 32 decimal digits past the decimal point:
9.10977222864644365500113714088140
9.10977222864644365500113714088140
</pre>
</pre>