# Vector Fields

5 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Vector Fields

 The document gnuplot.pdf, as a means of learning gnuplot "from the ground up," seems to be a lost cause.  It's the first time, in ten years of learning new programs, software and systems (and Java and FORTRAN), that I've run up against a genuinely unreadable manual.  It's main use for me is to remind me of certain things I figured out before but need to freshen up on after a week of disuse.   So I'll have to learn things by example.  I'm aware of the site http://gnuplot.sourceforge.net/demo/.  It's quite good for figuring out how to come up with pretty pictures of scalar-valued functions and surfaces, but now I want to be able to make simple vector fields.  All roads seem to lead to the same example: http://gnuplot.sourceforge.net/demo/vector.html.  But it's far too complicated and has too many other extraneous things (whoop-de-doo contour lines and other bells and whistles) for me to zero in on the code for making a simple 2D vector field.   Let F(x,y) =  be the vector field that assigns to each point (x,y) the vector , using the typical calculus text notation.  What code, minimally, will produce this vector field in the window [-5:5]x[-5:5] at points with, say, integer coordinates? Also, IS there any decent book or website out there that helps explain these things better?
Open this post in threaded view
|
Report Content as Inappropriate

 set xrange [-5:5] set yrange [-5:5] # only integer x-cordinates set samples 11 # only integer y-cordinates set isosamples 11 # we need data, so we use the special filename "++", which # produces x,y-pairs plot "++" using 1:2:1:(2.*$2) with vectors Soothfast wrote The document gnuplot.pdf, as a means of learning gnuplot "from the ground up," seems to be a lost cause. It's the first time, in ten years of learning new programs, software and systems (and Java and FORTRAN), that I've run up against a genuinely unreadable manual. It's main use for me is to remind me of certain things I figured out before but need to freshen up on after a week of disuse. So I'll have to learn things by example. I'm aware of the site http://gnuplot.sourceforge.net/demo/. It's quite good for figuring out how to come up with pretty pictures of scalar-valued functions and surfaces, but now I want to be able to make simple vector fields. All roads seem to lead to the same example: http://gnuplot.sourceforge.net/demo/vector.html. But it's far too complicated and has too many other extraneous things (whoop-de-doo contour lines and other bells and whistles) for me to zero in on the code for making a simple 2D vector field. Let F(x,y) = be the vector field that assigns to each point (x,y) the vector , using the typical calculus text notation. What code, minimally, will produce this vector field in the window [-5:5]x[-5:5] at points with, say, integer coordinates? Also, IS there any decent book or website out there that helps explain these things better? Reply | Threaded Open this post in threaded view | Report Content as Inappropriate ## Re: Vector Fields  Much appreciated, Thomas. Quite nice. So, one big problem I had with the gnuplot.pdf manual is that it gave no satisfactory explanation for how the "using" command works. As far as I could work out, "using 1:2:4" indicates using the first, second and fourth columns of data in a data file, but since no actual data file is ever shown and examples are sparse, I can not even remotely envision how things "connect" contextually. So, to fully understand your code, I have to know what at least one line of the "++" data file looks like. Putting "set table" into your code lets me see it, and I can see that the first line is -5 5 -5 10 i (Just an aside, but I find it odd that y starts at 5 instead of -5). Okay, so one more question, and then I'll go get the book "GNUplot in Action" and maybe become less of a pest: What about a direction field? That is, how can we make all the arrows in the vector field have the same length of, say, 0.5? It looks like the file "++" would need a fifth column 0.5*($3)/sqrt(($3)**2+($4)**2) and a sixth column 0.5*($4)/sqrt(($3)**2+($4)**2) (hope I have the syntax right) and then somehow get a plot of "++" using 1:2:5:6 with vectors. Am I close? (I'll be teaching a differential equations class in the spring.) Thomas Sefzick wrote set xrange [-5:5] set yrange [-5:5] # only integer x-cordinates set samples 11 # only integer y-cordinates set isosamples 11 # we need data, so we use the special filename "++", which # produces x,y-pairs plot "++" using 1:2:1:(2.*$2) with vectors
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Vector Fields

 the special filename "++" produces x,y-pairs, nothing more (gnuplot manual, chapter 65.2.14): -5 5 -5 4 ... to use these data for vectors you need to re-use the x- and y-data for the direction data which is needed for a vector (x,y,xdelta,ydelta; see gnuplot manual, chapter 44), here (x,y,xdelta=x,ydelta=2y): plot ... using 1:2:1:(2.*$2) with vectors to scale the vector length, scale xdelta and ydelta: plot ... using 1:2:(0.5*($1)/sqrt(($1)**2+($2)**2)):(0.5*(2.*$2)/sqrt(($1)**2+($2)**2)) ... 'set table' gives plot coordinates, but not input data. Soothfast wrote Much appreciated, Thomas. Quite nice. So, one big problem I had with the gnuplot.pdf manual is that it gave no satisfactory explanation for how the "using" command works. As far as I could work out, "using 1:2:4" indicates using the first, second and fourth columns of data in a data file, but since no actual data file is ever shown and examples are sparse, I can not even remotely envision how things "connect" contextually. So, to fully understand your code, I have to know what at least one line of the "++" data file looks like. Putting "set table" into your code lets me see it, and I can see that the first line is -5 5 -5 10 i (Just an aside, but I find it odd that y starts at 5 instead of -5). Okay, so one more question, and then I'll go get the book "GNUplot in Action" and maybe become less of a pest: What about a direction field? That is, how can we make all the arrows in the vector field have the same length of, say, 0.5? It looks like the file "++" would need a fifth column 0.5*($3)/sqrt(($3)**2+($4)**2) and a sixth column 0.5*($4)/sqrt(($3)**2+($4)**2) (hope I have the syntax right) and then somehow get a plot of "++" using 1:2:5:6 with vectors. Am I close? (I'll be teaching a differential equations class in the spring.) Thomas Sefzick wrote set xrange [-5:5] set yrange [-5:5] # only integer x-cordinates set samples 11 # only integer y-cordinates set isosamples 11 # we need data, so we use the special filename "++", which # produces x,y-pairs plot "++" using 1:2:1:(2.*$2) with vectors
 Got it.  Once again many thanks. I gave the matter some thought and concluded that there should be a way of producing nice 2D vector fields using TikZ/PGF, and in a surprisingly short amount of time I managed to make it happen.  The code below produces a direction field for the differential equation y'=y^2-1, along with a couple of solution curves.  Of course, the great advantage to this is that line thicknesses and text are automatically consistent with the look and layout of the parent document, and no external pdf files are necessary.  I don't imagine this route will be feasible when it comes to 3D vector fields (at least not feasible given my limited coding ability), so then gnuplot will probably be the only game in town. \documentclass[12pt]{amsart} \usepackage{graphicx} \usepackage{color} \usepackage{tikz,pgf}         \usetikzlibrary{calc,scopes,decorations.markings,decorations.pathmorphing,positioning,shapes.arrows,arrows} \definecolor{mediumblue}{RGB}{0,0,140} \begin{document} \begin{tikzpicture}[>=latex,scale=1.5]         \draw[<->] (-2.3,0) -- (2.4,0) node[below]{$x$};         \draw[<->] (0,-2.3) -- (0,2.4) node[left]{$y$};         \draw[red,thick] plot[smooth,tension=0.55,samples at={-2,-1.99,...,-1.01,-1.001,-1.0005,-1.00015}] ({0.5*ln((\x-1)/(\x+1))-2.549},{\x-0.02});         \draw[blue,thick] plot[smooth,tension=0.55,samples at={-0.975,-0.960,...,0.965}] ({0.5*ln((1-\x)/(\x+1))},{\x});         \foreach \x in {-2,-1,...,2}                 {                         \draw (\x,0.1) -- (\x,-0.1);                 }         \foreach \y in {-2,-1,...,2}                 {                         \draw (0.1,\y) -- (-0.1,\y);                 }         \foreach \x in {-2,-1.8,...,2}                 \foreach \y in {-2,-1.8,...,2}                         {                                 \pgfmathparse{0.18/sqrt(1+(\y*\y-1)^2)} \let\t\pgfmathresult                                 \draw[arrow,mediumblue] (\x,\y) -- +({\t*1},{\t*(\y*\y-1)});                         }         \draw (-0.1,1) node[left]{$1$};  \draw (-0.1,2) node[left]{$2$};         \draw (1,-0.1) node[below]{$1$};  \draw (2,-0.1) node[below]{$2$};         \draw[blue,fill=blue] (0,0) circle (1pt); \draw[red,fill=red] (-2,-2) circle (1pt);         \draw[blue] (0,0.2) node[right]{$(0,0)$};  \draw[red] (-2,-2) node[right]{$(-2,-2)$}; \end{tikzpicture} \end{document} To get little arrows styled to my liking, instead of line segments, I replaced [>=latex,scale=1.5] with: [>=latex,scale=1.5,decoration={markings, mark=at position 1.00 with {\arrow[line width=0.3pt,scale=0.4]{>};}},         arrow/.style={postaction={decorate},shorten >= 1pt,line width=0.3pt,line cap=round}] Thomas Sefzick wrote the special filename "++" produces x,y-pairs, nothing more (gnuplot manual, chapter 65.2.14): -5 5 -5 4 ... to use these data for vectors you need to re-use the x- and y-data for the direction data which is needed for a vector (x,y,xdelta,ydelta; see gnuplot manual, chapter 44), here (x,y,xdelta=x,ydelta=2y): plot ... using 1:2:1:(2.*$2) with vectors to scale the vector length, scale xdelta and ydelta: plot ... using 1:2:(0.5*($1)/sqrt(($1)**2+($2)**2)):(0.5*(2.*$2)/sqrt(($1)**2+(\$2)**2)) ... 'set table' gives plot coordinates, but not input data.