Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting a function with discrete x values in gnuplot

I need to plot a function f(x), where x is discrete set of values (in my case positive integers). I couldn't find a way to specify a step-size when using the range option and samples doesn't seem to be the right solution. Finally, I would like to approximate f(x) with a smooth function.

like image 679
eivanov Avatar asked Mar 06 '12 14:03

eivanov


Video Answer


2 Answers

I don't quite understand why samples is not the solution to your problem.

If I want to plot sin(x) on an interval between 0 and 10 with a point at every integer I use

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

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

Finally to tackle the approximation problem have a look at this website which discusses linear least squares fitting. For simple linear interpolation use lp instead of p.

like image 123
Azrael3000 Avatar answered Oct 27 '22 01:10

Azrael3000


Or alternatively, play around with the ceil(x) or floor(x) functions.

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

like image 30
Raphael Roth Avatar answered Oct 27 '22 01:10

Raphael Roth