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.

Im trying to plot the following function:

$f(x,y)$ = $\left\{\begin{matrix} (x+y) & (x,y) \in T \\ (x+y)^2 & (x,y) \notin T \end{matrix}\right.$

where $T= \{ y\leq -x+1, x\geq 0, y\geq 0 \}$

Im trying without success something like:

Plot3D[Piecewise[{{x + y, {y <= -x + 1, x>=0, y>=0}}, {(x + y)^2, y > -x + 1}}, 
  0], {x, -4, 4}, {y, -4, 4}, Boxed -> False, AxesOrigin -> {0, 0, 0}]

I dont know if the PieceWise function supports multiple conditions like ${y <= -x + 1, x>=0, y>=0}$ for some piece.

share|improve this question
4  
You need to combine the conditions with And instead of making a list. Piecewise[{{x + y, y <= -x + 1 && x >= 0 && y >= 0}, {(x + y)^2, True}}] will do. –  Rahul Narain Jun 9 at 0:16

2 Answers 2

up vote 3 down vote accepted

Try this.

p1 = Plot3D[(x + y), {x, -3, 3}, {y, -3, 3}, 
       RegionFunction -> Function[{x, y}, y <= -x + 1 && y >= 0 && x >= 0]];

p2 = Plot3D[(x + y)^2, {x, -3, 3}, {y, -3, 3}, 
       RegionFunction -> Function[{x, y}, 1 <= y + x || y + x <= 0 || y <=  0 || x <=  0]];

Show[p1, p2]

enter image description here

you can also use UnitStep to define your region and to generate one function.

share|improve this answer

You can do with Piecewise:

f[x_, y_] := 
 Piecewise[{{x + y, y <= -x + 1 && x >= 0 && y    >= 0}, {(x + y)^2, True}}]
plt = Plot3D[f[x, y], {x, -4, 4}, {y, -4, 4}, PlotRange -> {0, 64}, 
  MeshFunctions -> {(#1 + #2 &), #1 &, #2 &}, 
  Mesh -> {{1.}, {0}, {0}}, MeshStyle -> Red, BoundaryStyle -> None, 
  Boxed -> False, AxesOrigin -> {0, 0, 0}]

enter image description here

share|improve this answer

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.