0
对于gnuplot,我有一个很大的(随机生成的)数字列表,我想在总和中用作索引。我该怎么做?gnuplot:如何总结一个任意列表
这是我的意思。比方说,数字的列表是
list = [81, 37, 53, 22, 72, 74, 44, 46, 96, 27]
我有一个函数
我现在要绘制的函数,在区间(-pi,pi)
这是f(x,n)
作为n
运行通过数字总和在list
。
对于gnuplot,我有一个很大的(随机生成的)数字列表,我想在总和中用作索引。我该怎么做?gnuplot:如何总结一个任意列表
这是我的意思。比方说,数字的列表是
list = [81, 37, 53, 22, 72, 74, 44, 46, 96, 27]
我有一个函数
我现在要绘制的函数,在区间(-pi,pi)
这是f(x,n)
作为n
运行通过数字总和在list
。
如果你能控制你的列表的样子,请尝试以下操作:
num = 10
# Let the numbers be in a space separated string.
# We can access the individual numbers with the word(string, index) function.
list = "81 37 53 22 72 74 44 46 96 27"
f(x,n) = cos(n*x)
set terminal pngcairo
set output "sum_cos.png"
set xrange [-pi:pi]
set samples 1000
# Build the plot command as a macro.
plt_cmd = ""
do for [n=1:num] {
plt_cmd = sprintf("%s + f(x,%s)", plt_cmd, word(list,n))
}
# Check what we have done so far.
print plt_cmd
titlestring = "{/Symbol S} cos(n_i*x), i = 1 ...".num
# Finally plot the sum by evaluating the macro.
plot @plt_cmd title titlestring
这是结果:
你要什么绘制?函数或它的总和? – Peaceful