gnuplot:“sum [<var> = <start>:<end>] <expression>”策略

时间:2016-09-14 11:18:55

标签: python sum gnuplot

在下面的脚本中,我想绘制y(x)

enter image description here

和此函数u(x)

enter image description here

修改

绘制y(x)很容易,但我在绘制函数u(x)时遇到问题。

u(x)y(x)的功能相同,但每一步都是相同的。

因此,为了绘制u(x),我尝试了sum [<var> = <start>:<end>] <expression>策略。我已将此表示法实现为:

replot sum[x=1:6] y(x) with line lt -1 lw 1 lc 2 title "u(x)"

在以下脚本中:

 #

 set ylabel "y" font  ", 20"
 set xlabel 'x' font  ", 20"


 set format y "%9.4f"
 set xrange [1:6]

 set yrange [0:20]
 set xtics font ", 15"
 set ytics font ", 15"


 set key font ",17" # Changes the font of the letters of the legend

 y(x) = (2*x)/(x**2)
 plot y(x) with line lt -1 lw 1 lc 1 title "y(x)"
 replot sum[x=1:6] y(x) with line lt -1 lw 1 lc 2 title "u(x)"


 pause -1
 set term post enh color eps
 set output "y_x.eps"
 replot

我不确定sum[x=1:6] y(x)策略是否确实正在策划u(x)

为了检查这一点,我们可以执行以下操作:

我们知道:

enter image description here

那么,u(6)的gnuplot中的值是多少?如果您运行该脚本,则会得到:

enter image description here

缩放:

我发现u(6)的价值达到了2.0000,而不是3.5835

这让我觉得replot sum[x=1:6] u(x)没有绘制u(x_i)(第二个公式)

我如何绘制u(x)

enter image description here

编辑2

在此脚本中运行replot sum[i=1:6] y(i)

set ylabel "y" font  ", 20"
set xlabel 'x' font  ", 20"


 set format y "%9.4f"

 set xrange [1:6]

 set yrange [0:20]
 set xtics font ", 15"
 set ytics font ", 15"


 set key font ",17" # Changes the font of the letters of the legend

 y(x) = (2*x)/(x**2)
 plot y(x) with line lt -1 lw 1 lc 1 title "y(x)"


 replot sum[i=1:6] y(i) with line lt -1 lw 1 lc 2 title "u(x)"

 pause -1
 set term post enh color eps
 set output "y_x.eps"
 replot

产生以下内容:u(6) = 3.000

enter image description here

enter image description here

编辑3

使用y(x) = (2.*x)/(x**2)y(x) = (2.*x)/(x**2.),我得到u(6) = 4.9

enter image description here

enter image description here

编辑4

制作:

N=100
replot sum[i=0:N-1] y(1. + (i+0.5)*5./N)*5./N with line lt -1 lw 1 lc 5 title "sum(x)"

产生一个常数(青色线)y=3.58。这是求和的数值近似的结果。

enter image description here

我真正希望实现的是为u(x)的所有值绘制函数x_{i} ...在每一步i中,对所有前面的步骤求和执行,并生成新值u。我想绘制函数u(x) ...

1 个答案:

答案 0 :(得分:1)

实际上,实际绘制为u(x)的内容只是6*y(x),您可以检查是否在脚本中替换了行

plot y(x) with line lt -1 lw 1 lc 1 title "y(x)"

plot 6*y(x) with line lt -1 lw 1 lc 1 title "y(x)"

该行将与u(x)重合。

另请注意,函数y(x)[0, 6]区间内不可积,因为它的行为在01/x(在您的公式中,您将获得表达式{ {1}})。