smooth peaks in gnuplot

不问归期 提交于 2019-12-17 20:15:27

问题


I have datapoints f(x_i) at points x_i (function f not known, only numerically) with f(0) = 0. The data show a peaklike structure at small x, to be followed by a slow shoulder-falloff at larger x that sets in half-way down from the maximum. I want to plot smoothed lines through these data points. If I use bezier then indeed f(0)=0 is ok, but the peak is significantly (by about 25%), lowered. If I use acsplines then the peak looks somewhat better, but f(0) = 0 is not maintained. How can I smooth that dataset without loosing vital info (f(0)=0) or the peak-height of the distribution?


回答1:


Smoothing with acsplines draws an approximating cubic spline, which doesn't go through your original data points.

A better approach could be to use cubic splines smooth csplines, which go through all data points but may show overshoots for sharp peaks.

The probably best solution in your case is to use monotonic cubic splines, smooth mcsplines, which maintain the monotonicity and convexity of the original data points (see F.N. Fritsch and R.E. Carlson, "Monotone Piecewise Cubic Interpolation", SIAM Journal on Numerical Analysis 17, pp. 238-246 (1980)).

Here is a short example which shows these differences:

The test.dat file contains the points

0 0
0.2 1
0.4 10
0.6 80
1 30
2 20
3 13
4 7
5 2
6 1 
7 0

And the script to plot them is

set xzeroaxis
set style data lines
set samples 500
plot 'test.dat' u 1:2 smooth acsplines title 'acsplines', \
     '' u 1:2 smooth csplines title 'csplines', \
     '' u 1:2 smooth mcsplines lw 2 title 'mcsplines',\
     '' u 1:2 w p pt 7 title 'data points'



来源:https://stackoverflow.com/questions/30580471/smooth-peaks-in-gnuplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!