Initial release of Maemo 5 port of gnuplot
[gnuplot] / demo / vector.dem
1 #
2 # $Id: vector.dem,v 1.11 2006/07/12 17:21:14 tlecomte Exp $
3 #
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)
10
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)"
17 #
18       r(x,y)=sqrt(x*x+y*y)
19       v1(x,y)=  q1/(r((x-x0),y))
20       v2(x,y)=  q2/(r((x+x0),y))
21 #
22       vtot(x,y)=v1(x,y)+v2(x,y)
23 #
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)
35 #
36       coef=.7
37       x0=1.
38       q1=1
39       q2=-1
40       xmin=-10.
41       xmax=10.
42       ymin=-10.
43       ymax=10.
44 #
45 reset
46 unset autoscale
47 set xr [xmin:xmax]
48 set yr [ymin:ymax]
49 set isosam 31,31
50 #set view 0, 0, 1, 1
51 set view map
52 unset surface
53 set contour base
54 set cntrparam order 4
55 set cntrparam linear
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
58 #
59 set label "-q" at -1,0 center
60 set label "+q" at  1,0 center
61 splot vtot(x,y) w l
62 print "Now create a file with equipotential lines"
63 pause -1 "Hit return to continue"
64
65 set table "equipo2.tmp"
66 replot
67 unset table
68 reset
69 pause 0
70
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"
75 set isosam 31,31
76
77 set table "field2xy.tmp"
78 splot vtot(x,y) w l
79 unset table
80 pause 0
81
82 unset autoscale
83 set xr [xmin:xmax]
84 set yr [ymin:ymax]
85 set isosam 31,31
86 set key under Left reverse
87 plot "field2xy.tmp" u 1:2:(coef*dx1($1,$2)):(coef*dy1($1,$2)) w vec, \
88      "equipo2.tmp" w l
89 pause -1 "Hit return to continue"
90
91 reset
92