gnuplot / misc (1)
not so FAQ
|
その他もろもろ (その1)3項演算子 (A ? B : C) の使い方. 3項演算子は,C言語のそれと同様に働きます,と言うとあまりに不親切な gnuplot> set xrange [-5:5] gnuplot> plot x>0 ? exp(-x) : exp(4*x) ![]() 条件式を入れ子にすれば,もう少し複雑な関数を定義することも可能です. gnuplot> f(x)= (abs(x)<1) ? 100 : ( (abs(x)<2) ? 50 : ((abs(x)<3) ? 20: 10 )) gnuplot> set xrange [-5:5] gnuplot> set yrange [0:150] gnuplot> set sample 1000 gnuplot> plot f(x) この関数は,Xの絶対値が1未満では100,1以上2未満では50,2以上3未満で 途切れた関数. Gnuplot FAQにも書かれていますが,gnuplotはゼロでの除算のような数学的 gnuplot> f(x) = (abs(x)>pi/2) ? sin(x+pi/2) : 0 gnuplot> g(x) = (abs(x)>pi/2) ? sin(x) : 1/0 gnuplot> set xrange [-2*pi:2*pi] gnuplot> set yrange [-1:1] gnuplot> plot g(x) w l lw 2,f(x) ここでは2つの正弦関数f(x)とg(x)を定義して,比較しています.f(x)の方 ループの作り方. gnuplotのコマンドに reread と if というものがあり, 3次元プロットを回転させて,簡単なアニメーションにしてみましょう.回 theta = theta + 10 set view 60, theta splot exp(-x*x)*erf(y) if(theta<360) reread thetaの初期値や,その他の設定は別の所で行い, load gnuplot> set nokey gnuplot> set noxtics gnuplot> set noytics gnuplot> set noztics gnuplot> set border 0 gnuplot> set isosamples 40, 40 gnuplot> set hidden3d gnuplot> set xrange [ -5 : 5 ] gnuplot> set yrange [ -5 : 5 ] gnuplot> theta = 5 gnuplot> load "loop.plt" |