File: vector.dem

package info (click to toggle)
gnuplot 4.0.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,448 kB
  • ctags: 6,623
  • sloc: ansic: 63,562; lisp: 5,011; cpp: 970; sh: 900; makefile: 753; objc: 647; asm: 539; csh: 297; awk: 235; pascal: 192; perl: 44
file content (91 lines) | stat: -rw-r--r-- 2,531 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#
# $Id: vector.dem,v 1.7 2003/10/28 05:35:54 sfeam Exp $
#
# This file demonstrates new features in gnuplot 3.6
# -1- saving contour lines as a gnuplottable file
# -2- plotting a vector field on the same graph
# -3- manipulating columns using the '$1,$2' syntax.
# the example is taken here from Physics is the display of equipotential
# lines and electrostatic field for a dipole (+q,-q)

print "\n This file demonstrates new features in gnuplot 3.6"
print " -1- saving contour lines as a gnuplottable file"
print " -2- plotting a vector field on the same graph"
print " -3- manipulating columns using the '$1,$2' syntax."
print " the example is taken here from Physics is the display of equipotential"
print " lines and electrostatic field for a dipole (+q,-q)"
#
      r(x,y)=sqrt(x*x+y*y)
      v1(x,y)=  q1/(r((x-x0),y))
      v2(x,y)=  q2/(r((x+x0),y))
#
      vtot(x,y)=v1(x,y)+v2(x,y)
#
      e1x(x,y)= q1*(x-x0)/r(x-x0,y)**3
      e1y(x,y)= q1*(y)/r(x-x0,y)**3
      e2x(x,y)= q2*(x+x0)/r(x+x0,y)**3
      e2y(x,y)= q2*(y)/r(x+x0,y)**3
      etotx(x,y)=e1x(x,y)+e2x(x,y)
      etoty(x,y)=e1y(x,y)+e2y(x,y)
      enorm(x,y)=sqrt(etotx(x,y)*etotx(x,y)+etoty(x,y)*etoty(x,y))
      dx1(x,y)=coef*etotx(x,y)/enorm(x,y)
      dy1(x,y)=coef*etoty(x,y)/enorm(x,y)
      dx2(x,y)=coef*etotx(x,y)
      dy2(x,y)=coef*etoty(x,y)
#
      coef=.7
      x0=1.
      q1=1
      q2=-1
      xmin=-10.
      xmax=10.
      ymin=-10.
      ymax=10.
#
reset
unset autoscale
set xr [xmin:xmax]
set yr [ymin:ymax]
set isosam 31,31
set view 0, 0, 1, 1
unset surface
set contour base
set cntrparam order 4
set cntrparam linear
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 
set cntrparam points 5
#
set label "-q" at -1,0 center
set label "+q" at  1,0 center
splot vtot(x,y) w l
pause 0 "Now create a file with equipotential lines"
pause -1 "Hit return to continue"
set term push
set term table
set out "equipo2.dat"
rep
set out
set term pop
reset
plot "equipo2.dat" w l
pause 0 "Now create a x/y datafile for plotting with vectors "
pause 0 "and display vectors parallel to the electrostatic field"
pause -1 "Hit return to continue"
set isosam 31,31
set term push
set term table
set out "field2xy.dat"
splot vtot(x,y) w l
set out
set term pop
unset autoscale
set xr [xmin:xmax]
set yr [ymin:ymax]
set isosam 31,31
set key under Left reverse
plot "field2xy.dat" u 1:2:(coef*dx1($1,$2)):(coef*dy1($1,$2)) w vec, \
     "equipo2.dat" w l
pause -1 "Hit return to continue"

reset