4
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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]]
| improve this answer | |
$\endgroup$
  • $\begingroup$ I like your solution. Is there a way to have the tail of the vectors at the points? $\endgroup$ – Alejandro Marcos Aragon Jan 16 '16 at 18:07
  • $\begingroup$ Yes you can add 'VectorStyle->"LeftArrow' $\endgroup$ – Algohi Jan 16 '16 at 18:27
4
$\begingroup$

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

| improve this answer | |
$\endgroup$
3
$\begingroup$

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}];
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.