Building a function with discrete x values ​​in gnuplot

I need to build a function f(x) , where x is a discrete set of values ​​(in my case, positive integers). I could not find a way to specify the step size when using the range parameter, and the samples do not seem to be the right solution. Finally, I would like to approximate f(x) using a smooth function.

+4
source share
3 answers

I do not quite understand why the samples are not the solution to your problem.

If I want to plot sin (x) between 0 and 10 with a dot in each integer, I use

 set xrange [0:10] set sample 11 plot sin(x) wp 

Obviously, the number of samples is xmax-xmin + 1 (10 - 0 + 1 = 11).

Finally, to solve the approximation problem, check out this website for a discussion on linear least squares binding. For simple linear interpolation, use lp instead of p .

+6
source

Or, conversely, play around with ceil(x) or floor(x) .

Maybe look at this example: http://gnuplot.sourceforge.net/demo/prob2.html

+1
source

You can do:

 plot [1:12] '+' u ($0):(f($0)) 

Where, $0 will be replaced by 1, 2, ..., 12. You can even do it smoothly. For instance:

 f(x)=sin(2*x) plot [1:12] f(x) t 'the function'\ , '+' u ($0):(f($0)) t 'the points'\ , '+' u ($0):(f($0)) smooth cspline t 'the smooth' 
0
source

Source: https://habr.com/ru/post/1400015/


All Articles