# Mathematica VectorPlot with Piecewise arguments

Why won't this output the VectorPlot? It outputs number (that even seems correct for the application), but I can't get a picture out of them :(

BbuitenBolR[r_, \[Theta]_, R_] := Cos[\[Theta]] (1 - R (3 + R^2 - 3 R Coth[R])/r^3) /. R -> 1
BbuitenBolT[r_, \[Theta]_, R_] := -Sin[\[Theta]] (1 + R (3 + R^2 - 3 R Coth[R])/r^3) /. R -> 1
BbinnenBolR[r_, \[Theta]_, R_] := Cos[\[Theta]] (3 R)/Sinh[R] (r Cosh[r] - Sinh[r])/r^3 /. R -> 1
BbinnenBolT[r_, \[Theta]_, R_] := -Sin[\[Theta]] (3 R)/( 2 Sinh[R]) ((1 + r^2) Sinh[r] - r Cosh[r])/r^3 /. R -> 1
Br[r_, \[Theta]_, R_] := Piecewise[{{BbinnenBolR[r, \[Theta], R], r <= R}, {BbuitenBolR[r, \[Theta], R], r > R}}];
Bt[r_, \[Theta]_, R_] := Piecewise[{{BbinnenBolT[r, \[Theta], R], r <= R}, {BbuitenBolT[r, \[Theta], R], r > R}}];
Bx[x_, z_, R_] := x/ArcCos[z/Sqrt[x^2 + z^2]] Br[ArcCos[z/Sqrt[x^2 + z^2]], ArcCos[z/Sqrt[x^2 + z^2]], R] + z/ArcCos[z/Sqrt[x^2 + z^2]] Bt[ArcCos[z/Sqrt[x^2 + z^2]],  ArcCos[z/Sqrt[x^2 + z^2]], R]
Bz[x_, z_, R_] := z/ArcCos[z/Sqrt[x^2 + z^2]] Br[ArcCos[z/Sqrt[x^2 + z^2]], ArcCos[z/Sqrt[x^2 + z^2]], R] - x/ArcCos[z/Sqrt[x^2 + z^2]] Bt[ArcCos[z/Sqrt[x^2 + z^2]], ArcCos[z/Sqrt[x^2 + z^2]], R]
Manipulate[N[Bx[1, 1, R]], {R, 1, 10}]
Bz[1, 1, 1] // N

Manipulate[ VectorPlot[{N[Bx[x, z, R]], N[Bz[x, z, R]]}, {x, -10, 10}, {z, -10, 10}], {R, 1, 10}]


I'm sorry for the messy code, but Mathematica copy-pastes that way. I checked out the Piecewise examples and the VectorPlot examples, but no luck on combining the two :( Is there an alternative way to do this?

Thanks!

Your use of /. R -> 1 seems strange to me. What do you mean to accomplish with that?
Nevertheless, adding Hold gives output of some kind:
Manipulate[VectorPlot[Hold@{N[Bx[x, z, R]], N[Bz[x, z, R]]}, {x, -10, 10}, {z, -10, 10}], {R, 1, 10}]

• Yeah, that should be removed. I changed the function to use HeavisideTheta instead of Piecewise, and now it works as it should. Don't really know where I went wrong... Commented May 26, 2011 at 15:54