Results 1 to 3 of 3

Math Help - 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 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\{<br />
\begin{array}{c}<br />
 \left.\frac{k}{n},\text{if} f(x,y)\in \left[\frac{k}{n},\frac{k+1}{n}\right.\right), 0\leq k<n. \\<br />
 n, \text{if} f(x,y)>n\text{                                       }<br />
\end{array}<br />
\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
    4
    Awards
    2
    Use the If command in Mathematica: If[condition, output if true, output if false]. Hint, though: Mathematica doesn't understand 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 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: December 6th 2011, 03:16 PM
  2. Replies: 14
    Last Post: October 7th 2011, 09:45 PM
  3. parametric plot in wxMaxima (or Mathematica)
    Posted in the Math Software Forum
    Replies: 3
    Last Post: November 17th 2010, 08:04 PM
  4. Mathematica: Exporting a plot
    Posted in the Math Software Forum
    Replies: 6
    Last Post: March 4th 2010, 06:56 AM
  5. Mathematica plot
    Posted in the Math Software Forum
    Replies: 2
    Last Post: February 15th 2010, 11:41 PM

Search Tags


/mathhelpforum @mathhelpforum