Feigenbaum constant calculation: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Promote to task, lots of examples, little controversy) |
|||
Line 1,190: | Line 1,190: | ||
12 4.66920098 |
12 4.66920098 |
||
13 4.66920537</pre> |
13 4.66920537</pre> |
||
=={{header|Ruby}}== |
|||
{{trans|C#}} |
|||
<lang ruby>def main |
|||
maxIt = 13 |
|||
maxItJ = 10 |
|||
a1 = 1.0 |
|||
a2 = 0.0 |
|||
d1 = 3.2 |
|||
puts " i d" |
|||
for i in 2 .. maxIt |
|||
a = a1 + (a1 - a2) / d1 |
|||
for j in 1 .. maxItJ |
|||
x = 0.0 |
|||
y = 0.0 |
|||
for k in 1 .. 1 << i |
|||
y = 1.0 - 2.0 * y * x |
|||
x = a - x * x |
|||
end |
|||
a = a - x / y |
|||
end |
|||
d = (a1 - a2) / (a - a1) |
|||
print "%2d %.8f\n" % [i, d] |
|||
d1 = d |
|||
a2 = a1 |
|||
a1 = a |
|||
end |
|||
end |
|||
main()</lang> |
|||
{{out}} |
|||
<pre> i d |
|||
2 3.21851142 |
|||
3 4.38567760 |
|||
4 4.60094928 |
|||
5 4.65513050 |
|||
6 4.66611195 |
|||
7 4.66854858 |
|||
8 4.66906066 |
|||
9 4.66917155 |
|||
10 4.66919515 |
|||
11 4.66920026 |
|||
12 4.66920098 |
|||
13 4.66920537</pre> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |