loops - gnuplot--iteration to obtain variables in datafile -
let's i've got info called 'mydata.dat' in form
x y 0 0 1 1 2 2 4 3 8 4 16 5 i need find next things data:
slope points 0 5 1 5 2 5 3 5 4 5 y-intercept same pairs equation line connecting same pairsthen need plot the info , overlay lines; below image of i'm asking for.
i know how obtain the slope , y-intercept single pair of points, , plot info , equation of line. illustration points 1 , 5:
set table plot "mydata.dat" using 0:($0==0 ? y1=$2 : $2) plot "mydata.dat" using 0:($0==4 ? y5=$2 : $2) unset table m1 = (y5 - y1)/(5-1) b1 = y1 - m1*1 y1(x) = m1*x + b1 i'm new iteration (and gnuplot) , think there's wrong syntax. i've tried number of things , haven't worked. best guess in form
plot [i=1:4] using 0:($0==1 ? y.i=$1 : $1) [i=1:5]{ m.i = (y5 - y.i)/(5-i) b.i = y.i - m.i*1 y.i(x) = m.i*x + b.i } set multiplot plot "mydata.dat" w lp plot [i=1:4] y.1(x) unset multiplot so going wrong? gnuplot able concatencate loop counter variables?
your syntax incorrect. although there other ways want, instace using word(var,i), straightforward prepare have utilize eval evaluate string can concatenate variables:
do [i=1:5]{ eval "m".i." = (y5 - y".i.")/(5-".i.")" eval "b".i." = y".i." - m".i."*1" eval "y".i."(x) = m".i."*x + b".i } loops gnuplot
No comments:
Post a Comment