Gnuplot for a cycle in steps of less than 1

I tried to build the next

plot for [h=0:2:0.1] sin(h*x)

But it gives the following error:

gnuplot> plot for [h=0:2:0.1] sin(x*h)
                     ^
         Expecting iterator     for [<var> = <start> : <end> {: <incr>}]
         or for [<var> in "string of words"]

But the next line works just fine

plot for [h=0:2:1.1] sin(x*h)

Is this a mistake, or should it work that way? I mean, why doesn't it accept increments less than 1?

I am using the next version of gnuplot

G N U P L O T
Version 5.0 patchlevel 1    last modified 2015-06-07 
+4
source share
2 answers

Gnuplot only supports iterations with integer values ​​(see the section "For a cycle in a chart command", page 98). Values ​​smaller than 1are cast as a whole with 0, which is unacceptable. Use for example

plot for [h=0:3:1.5] sin(x*h) title sprintf('%.1f', h)

displays four curves with hrelevant values 0, 1, 2, 3. To use smaller values, you must scale the iteration value later:

plot for [h=0:20:1] sin(0.1*h*x)
+3

, - , . seq:

list(start,end,increment)=system(sprintf("seq %g %g %g", start, increment, end))
plot for [i in list(0.,1.,0.1)] sin(i*x)

enter image description here

gnuplot ( Karl ), , seq , :

start=0.; end=1.; inc=0.1
list = ""; a=start-inc; while (a<end) {list=list.sprintf(" %.3f",a=a+inc)}
plot for [i in list] sin(i*x)

, while gnuplot 4.6.

+1

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


All Articles