Feigenbaum constant calculation: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (→‎{{header|REXX}}: added an arrow indicating the last (correct) decimal digit (true value), added/changed whitespace and comments.)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 199:
</pre>
 
=={{header|C++ sharp|C#}}==
{{trans|C}}
<lang cpp>#include <iostream>
 
int main() {
const int max_it = 13;
const int max_it_j = 10;
double a1 = 1.0, a2 = 0.0, d1 = 3.2;
 
std::cout << " i d\n";
for (int i = 2; i <= max_it; ++i) {
double a = a1 + (a1 - a2) / d1;
for (int j = 1; j <= max_it_j; ++j) {
double x = 0.0;
double y = 0.0;
for (int k = 1; k <= 1 << i; ++k) {
y = 1.0 - 2.0*y*x;
x = a - x * x;
}
a -= x / y;
}
double d = (a1 - a2) / (a - a1);
printf("%2d %.8f\n", i, d);
d1 = d;
a2 = a1;
a1 = a;
}
 
return 0;
}</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|C#|C sharp}}==
{{trans|Kotlin}}
<lang csharp>using System;
Line 276 ⟶ 231:
}
}
}</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|C++}}==
{{trans|C}}
<lang cpp>#include <iostream>
 
int main() {
const int max_it = 13;
const int max_it_j = 10;
double a1 = 1.0, a2 = 0.0, d1 = 3.2;
 
std::cout << " i d\n";
for (int i = 2; i <= max_it; ++i) {
double a = a1 + (a1 - a2) / d1;
for (int j = 1; j <= max_it_j; ++j) {
double x = 0.0;
double y = 0.0;
for (int k = 1; k <= 1 << i; ++k) {
y = 1.0 - 2.0*y*x;
x = a - x * x;
}
a -= x / y;
}
double d = (a1 - a2) / (a - a1);
printf("%2d %.8f\n", i, d);
d1 = d;
a2 = a1;
a1 = a;
}
 
return 0;
}</lang>
{{out}}
Line 422:
13 4.66920537
</pre>
 
=={{header|Fōrmulæ}}==
 
In [https://wiki.formulae.org/Feigenbaum_constant_calculation this] page you can see the solution of this task.
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Fortran}}==
Line 535 ⟶ 527:
12 4.669201301
13 4.669198656</pre>
 
=={{header|Fōrmulæ}}==
 
In [https://wiki.formulae.org/Feigenbaum_constant_calculation this] page you can see the solution of this task.
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Go}}==
Line 679:
12 4.66920098
13 4.66920537</pre>
 
 
=={{header|Julia}}==
Line 733 ⟶ 732:
23 4.66920160910297781286849594159066394676896043144121209732784416240857379387701
</pre>
 
 
=={{header|Kotlin}}==
Line 922 ⟶ 920:
12 4.66920131329420
13 4.66920154578091</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2018.04.01}}
{{trans|Ring}}
 
<lang perl6>my $a1 = 1;
my $a2 = 0;
my $d = 3.2;
 
say ' i d';
 
for 2 .. 13 -> $exp {
my $a = $a1 + ($a1 - $a2) / $d;
do {
my $x = 0;
my $y = 0;
for ^2 ** $exp {
$y = 1 - 2 * $y * $x;
$x = $a - $x²;
}
$a -= $x / $y;
} xx 10;
$d = ($a1 - $a2) / ($a - $a1);
($a2, $a1) = ($a1, $a);
printf "%2d %.8f\n", $exp, $d;
}</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|Phix}}==
Line 1,080 ⟶ 1,038:
13 4.66920537
4.669205372040318</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.04.01}}
{{trans|Ring}}
 
<lang perl6>my $a1 = 1;
my $a2 = 0;
my $d = 3.2;
 
say ' i d';
 
for 2 .. 13 -> $exp {
my $a = $a1 + ($a1 - $a2) / $d;
do {
my $x = 0;
my $y = 0;
for ^2 ** $exp {
$y = 1 - 2 * $y * $x;
$x = $a - $x²;
}
$a -= $x / $y;
} xx 10;
$d = ($a1 - $a2) / ($a - $a1);
($a2, $a1) = ($a1, $a);
printf "%2d %.8f\n", $exp, $d;
}</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|REXX}}==
Line 1,192 ⟶ 1,191:
12 4.66920098
13 4.66920537</pre>
 
=={{header|Scala}}==
===Imperative, ugly===
10,333

edits