Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

1 Answer 1

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

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.