Results 1 to 3 of 3

Thread: How to plot a 2 variable piecewise function in Mathematica

  1. #1
    Junior Member
    Joined
    Oct 2009
    From
    London
    Posts
    42

    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 $\displaystyle f(x,y)=5-(x^2+y^2)$, how can a plot the first few values of the sequence defined below?

    $\displaystyle 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. \\
    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.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    A Plied Mathematician
    Joined
    Jun 2010
    From
    CT, USA
    Posts
    6,318
    Thanks
    7
    Awards
    2
    Use the If command in Mathematica: If[condition, output if true, output if false]. Hint, though: Mathematica doesn't understand $\displaystyle 0\le k<n$, so you have to either use nested If statements, or use logical connectives (&&, I think) to get both conditions correct.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Oct 2009
    From
    London
    Posts
    42
    the $\displaystyle 0\leq k<n$ 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.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. How to plot this equation in Mathematica
    Posted in the Math Software Forum
    Replies: 1
    Last Post: Dec 6th 2011, 03:16 PM
  2. Replies: 14
    Last Post: Oct 7th 2011, 09:45 PM
  3. parametric plot in wxMaxima (or Mathematica)
    Posted in the Math Software Forum
    Replies: 3
    Last Post: Nov 17th 2010, 08:04 PM
  4. Mathematica: Exporting a plot
    Posted in the Math Software Forum
    Replies: 6
    Last Post: Mar 4th 2010, 06:56 AM
  5. Mathematica plot
    Posted in the Math Software Forum
    Replies: 2
    Last Post: Feb 15th 2010, 11:41 PM

Search Tags


/mathhelpforum @mathhelpforum