Collatz問題 #24
plotのusing修飾子がごてごてし過ぎているので整理する。
次のような二つのユーザ定義関数
gnuplot> up(iter, flag, max) = flag == 1 ? (max - iter + 1) : (1/0) gnuplot> down(iter, flag, max) = flag != 1 ? (max - iter + 1) : (1/0)
を定義しておく。
$ ./collatz13 97 > p97.dat
で得られる100以下の初期値では最長経路を持つ初期値97からの経路データをプロットする。
gnuplot> set xlabel 'initial number' gnuplot> set ylabel 'number of iterations' gnuplot> unset key gnuplot> set logscale x gnuplot> set terminal png gnuplot> set output 'p97.png' gnuplot> m = 118 gnuplot> plot 'p97.dat' using 1:(up($2,$3,m)) w l, '' using 1:(down($2,$3,m)) w l lt 3 gnuplot> set output
長くなりすぎていたusing修飾子がすっきりした。
関数単独なので無くてもよさそうに見える関数upとdownを囲む括弧はusing修飾子の文法上必要である。
以前に求めた経路上の最大値9232まで下降と上昇の操作がせめぎ合いつつ大きくなった後、
半分にする操作が優位になって1に到達している。