2017-03-25 14 views
0

gnuplotでは、インデックスとして使用する(ランダムに生成された)番号の大きなリストがあります。どうすればいいのですか?gnuplot:任意のリストを合計する方法

ここが私の言いたいことです。私は今、数字によるf(x,n)nとして実行の合計である間隔(-pi,pi)に、機能をプロットする関数

​​

を持っているのは、番号のリストが

list = [81, 37, 53, 22, 72, 74, 44, 46, 96, 27] 

あるとしましょうlistにあります。

+0

プロットするかどう?関数またはその合計? – Peaceful

答えて

0

あなたのリストがどのように見えるかを制御することができた場合は、次のことを試してください。

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 

これが結果です:

sum of cosine functions

関連する問題