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$
1
  • 2
    $\begingroup$ Try Piecewise+VectorPlot. $\endgroup$ Commented Nov 20, 2013 at 18:58

1 Answer 1

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$
2
  • $\begingroup$ Thank you @Kuba. It is exactly what I was looking. $\endgroup$ Commented Nov 21, 2013 at 16:33
  • 1
    $\begingroup$ I cannot reproduce your result with Mathematica 10.4. See 115620 Can you? Thanks. $\endgroup$ Commented May 20, 2016 at 21:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.