5

This seemingly simple problem is giving me some trouble. I need to plot a vector field on a line, and for that I'm following what I found here. I try to create a mesh that contains two points and just plot vectors on it:

\[ScriptCapitalD] = MeshRegion[{{0, 1}, {1, 1}}, Line[{1, 2}]];
VectorPlot[{Sin[x], Cos[y]}, {x, y} \[Element] \[ScriptCapitalD]]

But I get the following error:

VectorPlot::idomdim:  does not have a valid dimension as a plotting domain. >>

What's wrong with this approach?

Peter Mortensen
  • 759
  • 4
  • 7

3 Answers3

5

I don't know how to make this with RegionFunctions but you could show the vectors along the Line[{{0, 1}, {1, 1}}] like this:

VectorPlot[{Sin[x], Cos[y]}, {x, 0, 1}, {y, 0.5, 1.5},
 AspectRatio -> 1/5,
 FrameTicks -> {True, {0.95, 1, 1.05}, False, False},
 GridLines -> {None, {1}},
 GridLinesStyle -> {Blue, Dashed},
 PlotRange -> {Automatic, {0.95, 1.05}}]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168
3

Well, here's a way that works when the number of seconds since Jan. 1, 1970 is odd (that is, it crashes the kernel every other time I execute it):

reg = MeshRegion[{{0, 1}, {1, 1.001}}, Line[{1, 2}]];
points = MeshCoordinates@ DiscretizeRegion[reg, MaxCellMeasure -> {"Length" -> 0.1}];
vf = Table[{p, {Sin[x], Cos[y]} /. Thread[{x, y} -> p]}, {p, points}];
ListVectorPlot[vf, VectorPoints -> All, 
 Frame -> {{False, False}, {True, False}}, AspectRatio -> Automatic]

Mathematica graphics

Maybe someone will find a way that doesn't randomly stumble over a bug.

A manual construction that doesn't crash:

vfvec[{p_, v_}, scale_: 1] := Arrow[{p, p + scale*v}];
Graphics[{Arrowheads[0.03], vfvec[#, 0.1]} & /@ vf,
 Frame -> {{False, False}, {True, False}}]

Mathematica graphics

If you want centered arrows like VectorPlot, then change vfvec to

vfvec[{p_, v_}, scale_: 1] := Arrow[{p - scale*v/2, p + scale*v/2}];
Michael E2
  • 235,386
  • 17
  • 334
  • 747
3

In my opinion the easy way to plot vectors over 1D curve is to used VectorPoints option:

points = Table[{i, 1}, {i, 0, 1, .1}];
VectorPlot[{Sin[x], Cos[y]}, {x, 0, 1}, {y, -1, 2}, 
 VectorPoints -> points, VectorScale -> {0.1, .2}, 
 Epilog -> Point[points]]
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78