Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
2  
Try Piecewise+VectorPlot. – Kuba Nov 20 '13 at 18:58
up vote 3 down vote accepted
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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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