3

I want to plot a function, let say, f(x) = 1-0.5^x. And I want to plot it at given discrete points: x = 4,8,12,16...32, with points connected with the linespoints style. No external file is supposed to be needed. I know there's a way to do it in matlab/octave but I want to do it in gnuplot (for consistent style, because I have many other figures drawn in gnuplot). I have searched for results about plotting functions over a continuous interval. But I can't find how I can explicitly set some x points to plot. Pre-generating the x's and y's into a file is a viable option but sounds stupid. Is there a way to do it on the fly in gnuplot?

1 Answer 1

4

For equidistant x-values like you mention you must only set xrange, xtics and the number of samples properly:

set xrange [4:32]
set samples (32 - 4)/4 + 1
set xtics 4
f(x) = 1 - 0.5**x
plot f(x) with linespoints pt 7 ps 2

In general you cannot define an array of value where you want the numbers to be computed. If you need a more sophisticated selection of sampling values, you could use the + special file name.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that's exactly what I want.
This helped me, partly: after some scaling and scrolling, the points get out of sync. How can I reset the state variables responsible for this, or is this only possible by restart?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.