Feigenbaum constant calculation: Difference between revisions

m
m (Updated description and link for Fōrmulæ solution)
 
(22 intermediate revisions by 14 users not shown)
Line 12:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V max_it = 13
V max_it_j = 10
V a1 = 1.0
Line 33:
d1 = d
a2 = a1
a1 = a</langsyntaxhighlight>
 
{{out}}
Line 54:
=={{header|Ada}}==
{{Trans|Ring}}
<syntaxhighlight lang="ada">
<lang Ada>
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Line 101:
feigenbaum;
end Main;
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 122:
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
{{Trans|Ring}}
<langsyntaxhighlight lang="algol68"># Calculate the Feigenbaum constant #
print( ( "Feigenbaum constant calculation:", newline ) );
Line 151:
a2 := a1;
a1 := a
OD</langsyntaxhighlight>
{{out}}
<pre>
Line 171:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f FEIGENBAUM_CONSTANT_CALCULATION.AWK
BEGIN {
Line 198:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 215:
13 4.66920537
</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">maxIt = 13 : maxItj = 13
a1 = 1.0 : a2 = 0.0 : d = 0.0 : d1 = 3.2
 
print "Feigenbaum constant calculation:"
print
print " i d"
print "======================"
 
for i = 2 to maxIt
a = a1 + (a1 - a2) / d1
for j = 1 to maxItj
x = 0.0 : y = 0.0
for k = 1 to 2 ^ i
y = 1 - 2 * y * x
x = a - x * x
next k
a -= x / y
next j
d = (a1 - a2) / (a - a1)
print rjust(i,3); chr(9); ljust(d,13,"0")
d1 = d
a2 = a1
a1 = a
next i</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">100 cls
110 mit = 13
120 mitj = 13
130 a1 = 1
140 a2 = 0
150 d = 0
160 d1 = 3.2
170 print "Feigenbaum constant calculation:"
180 print
190 print " i d"
200 print "==================="
210 for i = 2 to mit
220 a = a1+(a1-a2)/d1
230 for j = 1 to mitj
240 x = 0
250 y = 0
260 for k = 1 to 2^i
270 y = 1-2*y*x
280 x = a-x*x
290 next k
300 a = a-(x/y)
310 next j
320 d = (a1-a2)/(a-a1)
330 print using "###";i;" ";
335 print using "##.#########";d
340 d1 = d
350 a2 = a1
360 a1 = a
370 next i
380 end</syntaxhighlight>
 
==={{header|Just BASIC}}===
<syntaxhighlight lang="lb">maxit = 13 : maxitj = 13
a1 = 1.0 : a2 = 0.0 : d = 0.0 : d1 = 3.2
 
print "Feigenbaum constant calculation:"
print
print " i d"
print "==================="
 
for i = 2 to maxit
a = a1 + (a1 - a2) / d1
for j = 1 to maxitj
x = 0 : y = 0
for k = 1 to 2 ^ i
y = 1 - 2 * y * x
x = a - x * x
next k
a = a - (x / y)
next j
d = (a1 - a2) / (a - a1)
print i; tab(8); d
d1 = d
a2 = a1
a1 = a
next i</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">100 CLS
110 mit = 13
120 mitj = 13
130 a1 = 1
140 a2 = 0
150 d = 0
160 d1 = 3.2
170 PRINT "Feigenbaum constant calculation:"
180 PRINT
190 PRINT " i d"
200 PRINT "==================="
210 FOR i = 2 TO mit
220 a = a1 + (a1 - a2) / d1
230 FOR j = 1 TO mitj
240 x = 0
250 y = 0
260 FOR k = 1 TO 2 ^ i
270 y = 1 - 2 * y * x
280 x = a - x * x
290 NEXT k
300 a = a - (x / y)
310 NEXT j
320 d = (a1 - a2) / (a - a1)
330 PRINT USING "### ##.#########"; i; d
340 d1 = d
350 a2 = a1
360 a1 = a
370 NEXT i
380 END</syntaxhighlight>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">LET maxit = 13
LET maxitj = 13
LET a1 = 1.0
LET d1 = 3.2
 
PRINT "Feigenbaum constant calculation:"
PRINT
PRINT " i d"
PRINT "==================="
 
FOR i = 2 to maxit
LET a = a1 + (a1 - a2) / d1
FOR j = 1 to maxitj
LET x = 0
LET y = 0
FOR k = 1 to 2 ^ i
LET y = 1 - 2 * y * x
LET x = a - x * x
NEXT k
LET a = a - (x / y)
NEXT j
LET d = (a1 - a2) / (a - a1)
PRINT using "### ##.#########": i, d
LET d1 = d
LET a2 = a1
LET a1= a
NEXT i
END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="freebasic">maxIt = 13 : maxItj = 13
a1 = 1.0 : a2 = 0.0 : d = 0.0 : d1 = 3.2
 
print "Feigenbaum constant calculation:"
print "\n i d"
print "===================="
 
for i = 2 to maxIt
a = a1 + (a1 - a2) / d1
for j = 1 to maxItj
x = 0.0 : y = 0.0
for k = 1 to 2 ^ i
y = 1 - 2 * y * x
x = a - x * x
next k
a = a - x / y
next j
d = (a1 - a2) / (a - a1)
print i using("###"), chr$(9), d
d1 = d
a2 = a1
a1 = a
next i</syntaxhighlight>
 
=={{header|C}}==
{{trans|Ring}}
<langsyntaxhighlight lang="c">#include <stdio.h>
 
void feigenbaum() {
Line 246 ⟶ 425:
feigenbaum();
return 0;
}</langsyntaxhighlight>
 
{{output}}
Line 267 ⟶ 446:
=={{header|C sharp|C#}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="csharp">using System;
 
namespace FeigenbaumConstant {
Line 297 ⟶ 476:
}
}
}</langsyntaxhighlight>
{{out}}
<pre> i d
Line 315 ⟶ 494:
=={{header|C++}}==
{{trans|C}}
<langsyntaxhighlight lang="cpp">#include <iostream>
 
int main() {
Line 342 ⟶ 521:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> i d
Line 359 ⟶ 538:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio;
 
void main() {
Line 387 ⟶ 566:
a1 = a;
}
}</langsyntaxhighlight>
{{out}}
<pre> i d
Line 402 ⟶ 581:
12 4.66920099
13 4.66920555</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
Translated from Algol
<syntaxhighlight lang="Delphi">
 
 
procedure FeigenbaumConstant(Memo: TMemo);
{ Calculate the Feigenbaum constant }
const IMax = 13;
const JMax = 10;
var I,J,K: integer;
var A1,A2,D1,X,Y: double;
var A,D: double;
begin
Memo.Lines.Add('Feigenbaum constant calculation:');
{Set initial starting values for iterations}
A1:=1.0; A2:=0.0; D1:=3.2;
Memo.Lines.Add(' I A D');
for I:=2 to IMax do
begin
{Find next Bifurcation parameter, A}
A:=A1 + (A1 - A2) / D1;
for J:=1 to JMax do
begin
X:=0; Y:=0;
for K:=1 to 1 shl i do
begin
Y:=1 - 2 * y * x;
X:=A - X * X
end;
A:=A - X / Y
end;
{Use current and previous values of A}
{to calculate the Feigenbaum constant D }
D:= (A1 - A2) / (A - A1);
Memo.Lines.Add(Format('%2d %2.8f %2.8f',[I,A,D]));
D1:=D; A2:=A1; A1:=A;
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
Feigenbaum constant calculation:
I A D
2 1.31070264 3.21851142
3 1.38154748 4.38567760
4 1.39694536 4.60094928
5 1.40025308 4.65513050
6 1.40096196 4.66611195
7 1.40111380 4.66854858
8 1.40114633 4.66906066
9 1.40115329 4.66917155
10 1.40115478 4.66919515
11 1.40115510 4.66920028
12 1.40115517 4.66920099
13 1.40115519 4.66920555
</pre>
 
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight>
numfmt 6 0
a1 = 1 ; a2 = 0 ; d1 = 3.2
ipow2 = 4
for i = 2 to 13
a = a1 + (a1 - a2) / d1
for j = 1 to 10
x = 0 ; y = 0
for k = 1 to ipow2
y = 1 - 2 * y * x
x = a - x * x
.
a -= x / y
.
d = (a1 - a2) / (a - a1)
print i & " " & d
d1 = d ; a2 = a1 ; a1 = a
ipow2 *= 2
.
</syntaxhighlight>
 
=={{header|F#|F sharp}}==
{{trans|C#}}
<langsyntaxhighlight lang="fsharp">open System
 
[<EntryPoint>]
Line 429 ⟶ 691:
a2 <- a1
a1 <- a
0 // return an integer exit code</langsyntaxhighlight>
{{out}}
<pre> i d
Line 447 ⟶ 709:
=={{header|Factor}}==
{{trans|Raku}}
<langsyntaxhighlight lang="factor">USING: formatting io locals math math.ranges sequences ;
 
[let
Line 471 ⟶ 733:
exp d "%2d %.8f\n" printf
] each
]</langsyntaxhighlight>
{{out}}
<pre>
Line 490 ⟶ 752:
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran"> program feigenbaum
implicit none
 
Line 519 ⟶ 781:
print '(i4,f13.10)', i, d1
end do
end</langsyntaxhighlight>
{{out}}
<pre> i d
Line 543 ⟶ 805:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 25-0-2019
' compile with: fbc -s console
 
Line 575 ⟶ 837:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>Feigenbaum constant calculation:
Line 596 ⟶ 858:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Feigenbaum_constant_calculation}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. 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 storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Feigenbaum constant calculation 01.png]]
In '''[https://formulae.org/?example=Feigenbaum_constant_calculation this]''' page you can see the program(s) related to this task and their results.
 
'''Test case'''
 
[[File:Fōrmulæ - Feigenbaum constant calculation 02.png]]
 
[[File:Fōrmulæ - Feigenbaum constant calculation 03.png]]
 
=={{header|FutureBasic}}==
{{trans|Ring and Phix}}
<syntaxhighlight lang="futurebasic">
window 1, @"Feignenbaum Constant", ( 0, 0, 200, 300 )
 
_maxIt = 13
_maxItJ = 10
 
void local fn Feignenbaum
NSUInteger i, j, k
double a1 = 1.0, a2 = 0.0, d1 = 3.2
print "Feignenbaum Constant"
print " i d"
for i = 2 to _maxIt
double a = a1 + ( a1 - a2 ) / d1
for j = 1 to _maxItJ
double x = 0, y = 0
for k = 1 to fn pow( 2, i )
y = 1 - 2 * y * x
x = a - x * x
next
a = a - x / y
next
double d = ( a1 - a2 ) / ( a - a1 )
printf @"%2d. %.8f", i, d
d1 = d
a2 = a1
a1 = a
next
end fn
 
fn Feignenbaum
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre>
Feignenbaum Constant
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|Go}}==
{{trans|Ring}}
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 630 ⟶ 954:
func main() {
feigenbaum()
}</langsyntaxhighlight>
 
{{out}}
Line 648 ⟶ 972:
13 4.66920537
</pre>
 
 
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang="groovy">class Feigenbaum {
static void main(String[] args) {
int max_it = 13
Line 679 ⟶ 1,004:
}
}
}</langsyntaxhighlight>
{{out}}
<pre> i d
Line 696 ⟶ 1,021:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.List (mapAccumL)
 
feigenbaumApprox :: Int -> [Double]
Line 730 ⟶ 1,055:
(show <$> feigenbaumApprox 13)
where
justifyRight n c s = drop (length s) (replicate n c ++ s)</langsyntaxhighlight>
{{Out}}
<pre> 1 3.2185114220380866
Line 785 ⟶ 1,110:
=={{header|Java}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="java">public class Feigenbaum {
public static void main(String[] args) {
int max_it = 13;
Line 813 ⟶ 1,138:
}
}
}</langsyntaxhighlight>
{{out}}
<pre> i d
Line 830 ⟶ 1,155:
 
=={{header|jq}}==
<langsyntaxhighlight lang="jq">def feigenbaum_delta(imax; jmax):
def lpad: tostring | (" " * (4 - length)) + .;
def pp(i;x): "\(i|lpad) \(x)";
Line 848 ⟶ 1,173:
| .a -= (.x / .y) )
| .d = (.a1 - .a2) / (.a - .a1)
| .d1 = .d | .a2 = .a1 | .a1 = .a;
| .emit = pp($i; .d)
| .d1 =pp($i; .d) |) .a2) = .a1 | .a1 = .a;
.emit ) ) ;
feigenbaum_deltaFeigenbaum_delta(13; 10)
</syntaxhighlight>
</lang>
{{out}}
<syntaxhighlight lang="sh">
<lang sh>
Feigenbaum's delta constant incremental calculation:
i δ
Line 872 ⟶ 1,195:
12 4.669200975097843
13 4.669205372040318
</syntaxhighlight>
</lang>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia"># http://en.wikipedia.org/wiki/Feigenbaum_constant
 
function feigenbaum_delta(imax=23, jmax=20)
Line 898 ⟶ 1,221:
 
feigenbaum_delta()
</langsyntaxhighlight>{{out}}
<pre>
Feigenbaum's delta constant incremental calculation:
Line 929 ⟶ 1,252:
=={{header|Kotlin}}==
{{trans|Ring}}
<langsyntaxhighlight lang="scala">// Version 1.2.40
 
fun feigenbaum() {
Line 959 ⟶ 1,282:
fun main(args: Array<String>) {
feigenbaum()
}</langsyntaxhighlight>
 
{{output}}
Line 980 ⟶ 1,303:
=={{header|Lambdatalk}}==
Following the Python code in a recursive mode.
<langsyntaxhighlight lang="scheme">
{feigenbaum 11} // on my computer stackoverflow for values greater than 11
-> [3.2185114220380866,4.3856775985683365,4.600949276538056,4.6551304953919646,4.666111947822846,
Line 1,013 ⟶ 1,336:
else {- :a {/ :x :y}} }}}
 
</syntaxhighlight>
</lang>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">function leftShift(n,p)
local r = n
while p>0 do
Line 1,050 ⟶ 1,373:
a2 = a1
a1 = a
end</langsyntaxhighlight>
{{out}}
<pre> i d
Line 1,065 ⟶ 1,388:
12 4.66920098
13 4.66920537</pre>
 
=={{header|M2000 Interpreter}}==
Using decimal type (26 decimal places) is better for this calculation (this has the same output as FORTRAN). Variable maxitj can be change to lower values when the i get higher value. Although we can't go lower than 2. So here we can start with 13, and lower to 2 for 16th iteration of i
 
<syntaxhighlight lang="m2000 interpreter">
module Feigenbaum_constant_calculation (maxit as integer, c as single){
locale 1033 // show dot for decimal separator symbol
single maxitj=13
integer i, j
long k
decimal a1=1, a2, d , d1=3.2, y, x, a
print "Feigenbaum constant calculation:"
print
print format$("{0:-7} {1:-12} {2}","i", "δ","max j")
for i = 2 to maxit
a=a1+(a1-a2)/d1
for j = 1 to maxitj {x=0:y=0:for k=1 to 2&^i {y=1@-2@*y*x:x=a-x*x}:a-=x/y}
d=(a1-a2)/(a-a1)
print format$("{0::-7} {1:10:-12} {2::-5}",i, d, j-1)
maxitj-=c
d1=d:a2=a1:a1= a
next
}
profiler
Feigenbaum_constant_calculation 18, .7
print timecount
</syntaxhighlight>
{{out}}
<pre>
i δ max j
2 3.2185114220 13
3 4.3856775986 12
4 4.6009492765 12
5 4.6551304954 11
6 4.6661119478 10
7 4.6685485814 10
8 4.6690606606 9
9 4.6691715554 8
10 4.6691951560 7
11 4.6692002291 7
12 4.6692013133 6
13 4.6692015458 5
14 4.6692015955 5
15 4.6692016062 4
16 4.6692016085 3
17 4.6692016090 3
18 4.6692016091 2
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
{{trans|D}}
<langsyntaxhighlight Mathematicalang="mathematica">maxit = 13;
maxitj = 10;
a1 = 1.0;
Line 1,096 ⟶ 1,467:
,
{i, 2, maxit}
] // Grid</langsyntaxhighlight>
{{out}}
<pre>2 3.21851
Line 1,112 ⟶ 1,483:
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE Feigenbaum;
FROM FormatString IMPORT FormatString;
FROM LongStr IMPORT RealToStr;
Line 1,154 ⟶ 1,525:
 
ReadChar
END Feigenbaum.</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|Kotlin}}
<langsyntaxhighlight Nimlang="nim">import strformat
 
iterator feigenbaum(): tuple[n: int; δ: float] =
Line 1,187 ⟶ 1,558:
echo " i δ"
for n, δ in feigenbaum():
echo fmt"{n:2d} {δ:.8f}"</langsyntaxhighlight>
 
{{out}}
Line 1,205 ⟶ 1,576:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use Math::AnyNum 'sqr';
Line 1,230 ⟶ 1,601:
($a2, $a1) = ($a1, $a);
printf "%2d %17.14f\n", $i, $d1;
}</langsyntaxhighlight>
{{out}}
<pre> 2 3.21851142203809
Line 1,247 ⟶ 1,618:
=={{header|Phix}}==
{{trans|Ring}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">maxIt</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">maxItJ</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">10</span>
Line 1,270 ⟶ 1,641:
<span style="color: #000000;">a1</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">a</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,290 ⟶ 1,661:
=={{header|Python}}==
{{trans|D}}
<langsyntaxhighlight lang="python">max_it = 13
max_it_j = 10
a1 = 1.0
Line 1,311 ⟶ 1,682:
d1 = d
a2 = a1
a1 = a</langsyntaxhighlight>
{{out}}
<pre> i d
Line 1,329 ⟶ 1,700:
=={{header|Racket}}==
{{trans|C}}
<langsyntaxhighlight lang="racket">#lang racket
(define (feigenbaum #:max-it (max-it 13) #:max-it-j (max-it-j 10))
(displayln " i d" (current-error-port))
Line 1,348 ⟶ 1,719:
 
(module+ main
(feigenbaum))</langsyntaxhighlight>
{{out}}
<pre> i d
Line 1,370 ⟶ 1,741:
{{trans|Ring}}
 
<syntaxhighlight lang="raku" perl6line>my $a1 = 1;
my $a2 = 0;
my $d = 3.2;
Line 1,390 ⟶ 1,761:
($a2, $a1) = ($a1, $a);
printf "%2d %.8f\n", $exp, $d;
}</langsyntaxhighlight>
{{out}}
<pre> i d
Line 1,408 ⟶ 1,779:
=={{header|REXX}}==
{{trans|Sidef}}
<langsyntaxhighlight lang="rexx">/*REXX pgm calculates the (Mitchell) Feigenbaum bifurcation velocity, #digs can be given*/
parse arg digs maxi maxj . /*obtain optional argument from the CL.*/
if digs=='' | digs=="," then digs= 30 /*Not specified? Then use the default.*/
Line 1,440 ⟶ 1,811:
/*stick a fork in it, we're all done. */
say left('', 9 + 1 + 11 + 1 + t )"↑" /*show position of greatest accuracy. */
say ' true value= ' # / 1 /*true value of Feigenbaum's constant. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,471 ⟶ 1,842:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring"># Project : Feigenbaum constant calculation
 
decimals(8)
Line 1,501 ⟶ 1,872:
a2 = a1
a1 = a
next</langsyntaxhighlight>
Output:
<pre>Feigenbaum constant calculation:
Line 1,517 ⟶ 1,888:
12 4.66920098
13 4.66920537</pre>
 
=={{header|RPL}}==
{{trans|Python}}
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Python code
|-
|
≪ { }
13 10 → maxit maxitj
≪ 3.2 1 0
2 maxit 1 + '''FOR''' ii
DUP2 - 4 PICK / 3 PICK +
1 maxitj 1 + '''START'''
0 0
1 2 ii ^ '''START'''
OVER * 2 * 1 SWAP -
3 PICK ROT SQ - SWAP '''NEXT'''
/ - '''NEXT'''
3 PICK ROT - OVER 4 PICK - /
5 ROLL OVER + 5 ROLLD
4 ROLL DROP SWAP ROT '''NEXT'''
3 DROPN
≫ ≫
´'''FBAUM'''’ STO
|
'''FBAUM''' ''( -- { δ1..δ13 } )''
max_it, max_it_j = 13, 10
d1, a1, a2 = 3.2, 1, 0
for i in range(2, max_it + 1):
a = a1 + (a1 - a2) / d1
for j in range(1, max_it_j + 1):
x = y = 0
for k in range(1, (1 << i) + 1):
y = 1.0 - 2.0 * y * x
x = a - x * x
a = a - x / y
d = (a1 - a2) / (a - a1)
print(d)
d1, a2, a1 = d, a1, a
clean stack
.
.
|}
{{out}}
<pre>
1: { 3.21851142204 4.38567759857 4.60094927654 4.65513049539 4.66611194782 4.66854858152 4.66906066029 4.66917155686 4.6691951528 4.66920033694 4.66920090912 4.66920429563 4.66917851362 }
</pre>
The above program (limited at 10 iterations) takes 33 minutes and 50 seconds to be executed on a HP-28S.
 
=={{header|Ruby}}==
{{trans|C#}}
<langsyntaxhighlight lang="ruby">def main
maxIt = 13
maxItJ = 10
Line 1,546 ⟶ 1,967:
end
 
main()</langsyntaxhighlight>
{{out}}
<pre> i d
Line 1,564 ⟶ 1,985:
=={{header|Scala}}==
===Imperative, ugly===
<langsyntaxhighlight Scalalang="scala">object Feigenbaum1 extends App {
val (max_it, max_it_j) = (13, 10)
var (a1, a2, d1, a) = (1.0, 0.0, 3.2, 0.0)
Line 1,588 ⟶ 2,009:
}
 
}</langsyntaxhighlight>
===Functional Style, Tail recursive===
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/OjA3sae/0 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/04eS3BfCShmrA7I8ZmQfJA Scastie (remote JVM)].
<langsyntaxhighlight Scalalang="scala">object Feigenbaum2 extends App {
private val (max_it, max_it_j) = (13, 10)
 
Line 1,624 ⟶ 2,045:
result.foreach { case (δ, i) => println(f"${i + 2}%2d $δ%.8f") }
 
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">var a1 = 1
var a2 = 0
var δ = 3.2.float
Line 1,647 ⟶ 2,068:
(a2, a1) = (a1, a0)
printf("%2d %.8f\n", i, δ)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,671 ⟶ 2,092:
{{trans|C}}
 
<langsyntaxhighlight lang="swift">import Foundation
 
func feigenbaum(iterations: Int = 13) {
Line 1,705 ⟶ 2,126:
}
 
feigenbaum()</langsyntaxhighlight>
 
{{out}}
Line 1,725 ⟶ 2,146:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
Sub Main()
Line 1,753 ⟶ 2,174:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre> i d
Line 1,768 ⟶ 2,189:
12 4.66920098
13 4.66920537</pre>
 
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">fn feigenbaum() {
max_it, max_itj := 13, 10
mut a1, mut a2, mut d1 := 1.0, 0.0, 3.2
println(" i d")
for i := 2; i <= max_it; i++ {
mut a := a1 + (a1-a2)/d1
for j := 1; j <= max_itj; j++ {
mut x, mut y := 0.0, 0.0
for k := 1; k <= 1<<u32(i); k++ {
y = 1.0 - 2.0*y*x
x = a - x*x
}
a -= x / y
}
d := (a1 - a2) / (a - a1)
println("${i:2} ${d:.8f}")
d1, a2, a1 = d, a1, a
}
}
fn main() {
feigenbaum()
}</syntaxhighlight>
 
{{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|Wren}}==
{{trans|Ring}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
 
var feigenbaum = Fn.new {
Line 1,800 ⟶ 2,264:
}
 
feigenbaum.call()</langsyntaxhighlight>
 
{{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|XPL0}}==
{{trans|Wren}}
<syntaxhighlight lang "XPL0">def MaxIt = 13, MaxItJ = 10;
real A, A1, A2, D, D1, X, Y;
int I, J, K;
[A1:= 1.; A2:= 0.; D1:= 3.2;
Text(0, " i d^m^j");
for I:= 2 to MaxIt do
[A:= A1 + (A1-A2)/D1;
for J:= 1 to MaxItJ do
[X:= 0.; Y:= 0.;
for K:= 1 to 1<<I do
[Y:= 1. - 2.*Y*X;
X:= A - X*X;
];
A:= A - X/Y;
];
D:= (A1-A2) / (A-A1);
Format(2, 0); RlOut(0, float(I));
Format(5, 8); RlOut(0, D);
CrLf(0);
D1:= D;
A2:= A1;
A1:= A;
];
]</syntaxhighlight>
{{out}}
<pre>
Line 1,821 ⟶ 2,328:
=={{header|zkl}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="zkl">fcn feigenbaum{
maxIt,maxItJ,a1,a2,d1,a,d := 13, 10, 1.0, 0.0, 3.2, 0, 0;
println(" i d");
Line 1,835 ⟶ 2,342:
d1,a2,a1 = d,a1,a;
}
}();</langsyntaxhighlight>
{{out}}
<pre>
2,053

edits