我想绘制两个函数:sin(x)和一个采样和量化的sin(x)。脚本很简单
set xtic 1
set ytic 1
f1(x) = sin(x/16*2*pi)*8
round(x) = x - floor(x) < 0.5 ? floor(x) : ceil(x)
plot [0:16] [-8.5:8.5] f1(x) with lines, round(f1(x)) with steps lt 2
问题是,我希望sin(x)是平滑的,采样的量化sin(x)以1的间隔采样。问题是,我找不到任何选项。添加
set sample 21
几乎可以工作,但是罪(x)看起来不够平滑。有没有办法让它变得更好?
答案 0 :(得分:7)
将f1()
而不是f1()
本身的变量四舍五入,并使用floor()
代替round()
plot [0:16] [-8.5:8.5] f1(x) with lines, f1(floor(x)+0.0) with steps lt 2
另外,设置大量样本以保持量化图正确对齐:
set samples 1000
如果您使用round()
代替floor
,则量化步长为“0.5步”(0.5至1.5,1.5至2.5等),而不是“1步”。