Fibonacci numbers in gnuplot
Example for versions
gnuplot 4.2.2
gnuplot provides no loops, and printing each number with a separate print
command makes it appear on separate line, so a string variable res
is used to accumulate the calculated numbers for printing after “looping”.
### run.gp
#!/usr/bin/env gnuplot
i = 1
a = 1
b = 1
res = ''
load "fibonacci.gp"
print res, '...'
### fibonacci.gp
res = res . a . ', '
c = a
a = b
b = b+c
i = i+1
if (i <= 16) reread
Comments
]]>blog comments powered by Disqus
]]>