MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: PlotVectorField

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34819] Re: PlotVectorField
  • From: shollis at armstrong.edu (Selwyn Hollis)
  • Date: Sat, 8 Jun 2002 05:21:34 -0400 (EDT)
  • References: <adpg01$j55$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I guess my original question was a bit cryptic, but Wolf's reply got
me thinking in the right direction. Actually what I was trying to do
was to overlay a vector field with several curves created with
ListPlot. The points given to ListPlot typically spill out beyond the
rectangle on which I want to plot, so I needed so way to restrict the
plot to the desired rectangle. PlotRange is the obvious way, but it
leads to the difficulties I was trying to describe.

Anyway, I wonder what you all think about the following fix: Instead
of using PlotRange, I apply a ``pullback" function to the list of
points to make sure they all lie in the rectangle I want before I give
the list to ListPlot. The only points in the list that can possibly
spill out of the rectangle are the first and the last. So I made the
following functions for each edge of the rectangle a<=x<=b, c<=y<=d.
Each one just replaces the first/last point in the list with a convex
combination of first two/last two points in such a way that the result
is on the edge of the rectangle.

pulla[z_,a_]:= Module[{r=(z[[1,1]]-a)/(z[[1,1]]-z[[2,1]])},
    ReplacePart[z, r*z[[2]]+(1-r)*z[[1]], 1]];
pullb[z_,b_]:= Module[{r=(z[[-1,1]]-b)/(z[[-1,1]]-z[[-2,1]])},
    ReplacePart[z, r*z[[-2]]+(1-r)*z[[-1]], -1]];
pullc[z_,c_]:= Module[{r=(z[[1,2]]-c)/(z[[1,2]]-z[[2,2]])},
    ReplacePart[z, r*z[[2]]+(1-r)*z[[1]], 1]];
pulld[z_,d_]:= Module[{r=(z[[-1,2]]-d)/(z[[-1,2]]-z[[-2,2]])},
    ReplacePart[z, r*z[[-2]]+(1-r)*z[[-1]], -1]];

Then I put everything together like this:
 
pullback[z_?MatrixQ,{a_,b_,c_,d_}]:=Module[{zz=z},
 If[If[If[If[If[If[If[If[zz[[1,1]]<a,
         zz=pulla[zz,a],zz][[1,2]]<c,
        zz=pullc[zz,c],zz][[-1,1]]>b,
       zz=pullb[zz,b],zz][[-1,2]]>d,
      zz=pulld[zz,d],zz][[-1,1]]<a,
     zz=pullb[zz,a],zz][[-1,2]]<c,
    zz=pulld[zz,c],zz][[1,1]]>b,
   zz=pulla[zz,b],zz][[1,2]]>d,
  zz=pullc[zz,d],zz];zz]; 

Now, pullback[pointlist, {a,b,c,d}] gives points that all lie in the
desired rectangle and still accurately produce the curve.

If anyone has an ideas as to how this pullback function can be written
is a more ``MC" (Mathematica-ly Correct) way, I'd appreciate your
advice.

Cheers,
Selwyn


  • Prev by Date: Re: Is it possible to access internal variables?
  • Next by Date: Re: puzzling difference in speed
  • Previous by thread: RE: PlotVectorField
  • Next by thread: RE: Re: PlotVectorField