2 # $Id: vector.dem,v 1.11 2006/07/12 17:21:14 tlecomte Exp $
4 # This file demonstrates
5 # -1- saving contour lines as a gnuplottable file
6 # -2- plotting a vector field on the same graph
7 # -3- manipulating columns using the '$1,$2' syntax.
8 # the example is taken here from Physics is the display of equipotential
9 # lines and electrostatic field for a dipole (+q,-q)
11 print "\n This file demonstrates
12 print " -1- saving contour lines as a gnuplottable file"
13 print " -2- plotting a vector field on the same graph"
14 print " -3- manipulating columns using the '$1,$2' syntax."
15 print " the example is taken here from Physics is the display of equipotential"
16 print " lines and electrostatic field for a dipole (+q,-q)"
19 v1(x,y)= q1/(r((x-x0),y))
20 v2(x,y)= q2/(r((x+x0),y))
22 vtot(x,y)=v1(x,y)+v2(x,y)
24 e1x(x,y)= q1*(x-x0)/r(x-x0,y)**3
25 e1y(x,y)= q1*(y)/r(x-x0,y)**3
26 e2x(x,y)= q2*(x+x0)/r(x+x0,y)**3
27 e2y(x,y)= q2*(y)/r(x+x0,y)**3
28 etotx(x,y)=e1x(x,y)+e2x(x,y)
29 etoty(x,y)=e1y(x,y)+e2y(x,y)
30 enorm(x,y)=sqrt(etotx(x,y)*etotx(x,y)+etoty(x,y)*etoty(x,y))
31 dx1(x,y)=coef*etotx(x,y)/enorm(x,y)
32 dy1(x,y)=coef*etoty(x,y)/enorm(x,y)
33 dx2(x,y)=coef*etotx(x,y)
34 dy2(x,y)=coef*etoty(x,y)
56 set cntrparam levels discrete -3,-2 ,-1 ,-0.5 ,-0.2 ,-0.1 ,-0.05 ,-0.02 ,0 ,0.02 ,0.05 ,0.1 ,0.2 ,0.5 ,1 ,2 ,3
57 set cntrparam points 5
59 set label "-q" at -1,0 center
60 set label "+q" at 1,0 center
62 print "Now create a file with equipotential lines"
63 pause -1 "Hit return to continue"
65 set table "equipo2.tmp"
71 plot "equipo2.tmp" w l
72 print "Now create a x/y datafile for plotting with vectors "
73 print "and display vectors parallel to the electrostatic field"
74 pause -1 "Hit return to continue"
77 set table "field2xy.tmp"
86 set key under Left reverse
87 plot "field2xy.tmp" u 1:2:(coef*dx1($1,$2)):(coef*dy1($1,$2)) w vec, \
89 pause -1 "Hit return to continue"