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