3
$\begingroup$

I am plotting this vector field:

Q[k_, N_] := Show[ContourPlot[3 - 3 BesselJ[0, r[x, y] a^-1], {x, -N, N}, {y, -N, N}, 
ContourStyle -> Opacity[0.3]], 

StreamPlot[{Sin[θ[x, y]], -Cos[θ[x, y]]}, {x, -N, N}, {y, -N, N}, 
PlotRange -> {Full, Full}, RegionFunction -> 
Function[{x, y}, a^2 - a^2/100 < x^2 + y^2 <=  a^2 + a^2/100], 
StreamStyle -> Red, StreamPoints -> {pts, Automatic, Scaled[2]}, 
StreamScale -> None],

StreamPlot[{Abs[(1 - a/r[x, y])^(1/2)] + 
a^(1/2)/r[x, y]^(1/2) Cos[θ[x, y] k], 
a^(1/2)/r[x, y]^(1/2) Sin[θ[x, y] k]}, {x, -N, N}, {y, -N, 
N}, PlotRange -> {Full, Full}, 
RegionFunction -> Function[{x, y}, x^2 + y^2 > a^2], 
StreamStyle -> {Blue, Thick, "Line"}, PerformanceGoal -> "Quality", 
StreamScale -> Full], 

ImageSize -> Large]     

with

r[x_, y_] := Sqrt[x^2 + y^2];
θ[x_, y_] := ArcTan[x, y];

a = 3;
pts = Flatten[
Table[{x, y}, {x, -a - a/10, a + a/10, 0.1}, {y, a - a/10, a + a/10, 0.1}], 1];

But I can't find a set of StreamPoints to avoid the segmentation of the lines near the x-axes.

Q[1/2,10]

enter image description here

Any ideas? Thanks!

$\endgroup$
0

1 Answer 1

4
$\begingroup$
r[x_, y_] := Sqrt[x^2 + y^2];
θ[x_, y_] := ArcTan[x, y];

a = 3;
pts = Flatten[Table[{x, y}, {x, -a - a/10, a + a/10, 0.1}, {y, a - a/10, a + a/10, 0.1}], 1];

Q[k_, n_] := Module[{pts1}, pts1 = Table[{0, x}, {x, -2 n, 2 n, 1/2}];
  Show[ContourPlot[ 3 - 3 BesselJ[0, r[x, y] a^-1], {x, -n, n}, {y, -n, n}, 
                   ContourStyle -> Opacity[0.3]], 
       StreamPlot[{Sin[θ[x, y]], -Cos[θ[x, y]]}, {x, -n, n}, {y, -n, n}, PlotRange -> {Full, Full}, 
                 RegionFunction -> Function[{x, y}, a^2 - a^2/100 < x^2 + y^2 <= a^2 + a^2/100], 
                 StreamStyle -> Red, StreamPoints -> {pts, Automatic, Scaled[2]},  
                 StreamScale -> None], 
       StreamPlot[{Abs[(1 - a/r[x, y])^(1/2)] +  a^(1/2)/r[x, y]^(1/2) Cos[θ[x, y] k], 
                      a^(1/2)/r[x, y]^(1/2) Sin[θ[x, y] k]}, {x, -2 n, 2 n}, {y, -2 n, 2 n}, 
                 RegionFunction -> Function[{x, y}, x^2 + y^2 > a^2 && Abs@x < n && Abs@y < n], 
                 StreamPoints -> {pts1, Automatic, Scaled[2]}, StreamStyle -> {Blue, Thick, "Line"}, 
                 PerformanceGoal -> "Quality", StreamScale -> Full], 
   ImageSize -> Large]]

Q[1/2, 10]

Mathematica graphics

$\endgroup$
8
  • $\begingroup$ Add more points as you see fit $\endgroup$ Feb 3, 2015 at 19:51
  • $\begingroup$ Thanks! How do I add more lines (i.e. starting points) on the left? I can't quite manage it! $\endgroup$ Feb 4, 2015 at 16:16
  • $\begingroup$ @usumdelphini Updated the code to do that $\endgroup$ Feb 4, 2015 at 16:55
  • $\begingroup$ I tried, but it doesn't show me the full lines for some reason, but only the parts near the edges of the frame $\endgroup$ Feb 4, 2015 at 17:13
  • $\begingroup$ @usumdelphini Try it on a clean (new) Mathematica session. If it doesn't work it's probably because of a version mismatch issue. I'm using Mathematica 9. $\endgroup$ Feb 4, 2015 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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