3
$\begingroup$

I want to plot a piecewise-smooth vector field. For instance:

$F_1(x,y) = (x^2 + y^2, y^2)$, $F_2 (x,y) = (2xy,2xy-x^2)$ and $H(x,y) = x-y$

$F(x,y) = \begin{cases} F_1(x,y) \text{ if } H(x,y) >0 \\ F_2(x,y) \text{ if } H(x,y)<0 \end{cases}$

How can I plot $F(x,y)$ in Mathematica?

$\endgroup$
  • 2
    $\begingroup$ Try Piecewise+VectorPlot. $\endgroup$ – Kuba Nov 20 '13 at 18:58
4
$\begingroup$
f1[x_, y_] := {x^2 + y^2, y^2}
f2[x_, y_] := {2 x y, 2 x y - x^2}
h[x_, y_] := x - y

f[x_, y_] := Piecewise[{{f1[x, y], h[x, y] >= 0}, {f2[x, y], h[x, y] < 0}}]

VectorDensityPlot[f[x, y], {x, -5, 5}, {y, -5, 5}, VectorStyle -> Directive[Red], 
                           VectorScale -> Large, ColorFunctionScaling -> True,
                           ColorFunction -> (GrayLevel[Sign@h[#, #2]] &)
                 ]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you @Kuba. It is exactly what I was looking. $\endgroup$ – jon jones Nov 21 '13 at 16:33
  • 1
    $\begingroup$ I cannot reproduce your result with Mathematica 10.4. See 115620 Can you? Thanks. $\endgroup$ – bbgodfrey May 20 '16 at 21:56

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.