gnuplot / misc (1E)
not so FAQ |
Miscellaneous Stuff (No.1)Ternary operator (A ? B : C) The ternary operator works just the same as that in C-language. gnuplot> set xrange [-5:5] gnuplot> plot x>0 ? exp(-x) : exp(4*x) ![]() More complicated functions can be definced with this ternary 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) This function gives 100 if the absolute value of X is less than 1, Broken functions Gnuplot ignores any mathematically undefined expressions like zero 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) We comapre two sine functions, f(x) and g(x). f(x) is zero when |x| is smaller Loop Gnuplot has a reread and if commands. With Let’s make a simple animation by rotating a 3D plot. To rotate the theta = theta + 10 set view 60, theta splot exp(-x*x)*erf(y) if(theta<360) reread An initial value of theta and the other setting are given 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" |