# Math Help - How to plot a 2 variable piecewise function in Mathematica

1. ## How to plot a 2 variable piecewise function in Mathematica

Hello I want to plot a sequence of functions (actually just the first few n, say for n=1,2,3).

Given an arbitrary function say a parabloid $f(x,y)=5-(x^2+y^2)$, how can a plot the first few values of the sequence defined below?

$f_n(x,y)=\left\{
\begin{array}{c}
\left.\frac{k}{n},\text{if} f(x,y)\in \left[\frac{k}{n},\frac{k+1}{n}\right.\right), 0\leq k n, \text{if} f(x,y)>n\text{ }
\end{array}
\right.$

Something like a countour plot would be perfect if a 3d is hard to do.

2. Use the If command in Mathematica: If[condition, output if true, output if false]. Hint, though: Mathematica doesn't understand $0\le k, so you have to either use nested If statements, or use logical connectives (&&, I think) to get both conditions correct.

3. the $0\leq k is just different values of the function on different intervals. so maybe multiple if statements are needed, or maybe a for loop. I've never written mathematica code before. but i'll try it out, thanks, some help on getting started would be appreciated. I'm not sure on how to define a function using an if statement.

i'm only used to seeing, g(x_, y_):=5-(x^2 + y^2) type definitions.