2013-04-06 159 views
5

任何人都可以告诉我如何使用gnuplot绘制复杂的指数。我试图用这个脚本来绘制它们,但是无法识别参数iGnuplot和复杂的指数

set terminal epslatex color colortext size 9cm,5cm 
set size 1.5,1.0 
set output "eulerjeva_identiteta_1.tex" 

set style line 1 linetype 1 linewidth 3 linecolor rgb "#FF0055" 
set style line 2 linetype 2 linewidth 1 linecolor rgb "#FF0055" 
set style line 3 linetype 1 linewidth 3 linecolor rgb "#2C397D" 
set style line 4 linetype 2 linewidth 1 linecolor rgb "#2C397D" 
set style line 5 linetype 1 linewidth 3 linecolor rgb "#793715" 
set style line 6 linetype 2 linewidth 1 linecolor rgb "#793715" 
set style line 7 linetype 1 linewidth 3 linecolor rgb "#b1b1b1" 
set style line 8 linetype 3 linewidth 1 linecolor rgb "#b1b1b1" 

set grid 

set samples 7000 

set key at graph .95, 0.4 
set key samplen 2 
set key spacing 0.8 

f(x) = exp(i*x) 
g(x) = exp(-i*x) 
h(x) = exp(i*x)+exp(-i*x) 

set xrange [-2*pi:2*pi] 
set yrange [-1.2:1.2] 

set xtics ("$0$" 0, "$\\pi$" pi, "$-\\pi$" -pi) 
set ytics ("$1$" 1, "$-1$" -1) 

set xlabel "$x$" 

plot [-2*pi:2*pi] f(x) ls 1 title "$\\e^{ix}$", g(x) ls 3 title "$\\e^{-ix}$", h(x) ls 5 title "$\\e^{ix} + \\e^{-ix}$" 

回答

13

gnuplot的不理解isqrt(-1),因为变量i没有被gnuplot的赋值 - 它只是另一个变量名就其所涉事宜。 gnuplot的可使用格式

z = {a,b} 

其表示在写入符号的复数z = (a + ib)理解和操纵复数。所以,我可以定义

i = {0.0,1.0} 

还有的时候你再图

plot exp(i*x) 

所有点“未定义”,因为他们有一个虚构的成分,你会得到什么问题。 (虽然,h(x) = exp(i*x)+exp(-i*x)会打好,因为它纯粹是真实的。)问题是,gnuplot只能绘制实数。你可以尝试

plot real(exp(i*x)), imag(exp(i*x)) 

单独可视化组件,或者你可以做一个参数图:

set parametric 
plot real(exp(i*t)), imag(exp(i*t)) 
+0

有没有办法欺骗?我的意思是画一些sin函数,而不是e^ix? – 71GA 2013-04-06 20:50:20

+0

因为exp(i * x)= cos(x)+ i * sin(x),我认为这将是'plot imag(exp(i * x))'。 – andyras 2013-04-06 22:39:41

+0

注意'exp(ix)= cos(x)+ i sin(x)'。 – Bernhard 2014-03-19 12:01:56