Results 1 to 3 of 3

Math Help - Mathematica discrete functions

  1. #1
    Junior Member
    Joined
    Dec 2009
    From
    Texas
    Posts
    70
    Awards
    1

    Mathematica discrete functions

    Hello,

    What I want to be able to do with Mathematica is define a discrete function with a discrete domain and range that I create and designate. For example:

    A = \{a, b, c, d\}

    B = \{1, 2, 9, \pi\}

     f: A \rightarrow B

    f(x) = \begin{cases} 1 &\text{ if }x = a\\2 &\text{ if }x = c\\ \pi &\text{ if }x = b\\ 9 &\text{ if }x = d \end{cases}

    So that when I type f[a] in Mathematica, it spits out 1, f[b] spits out \pi, etc.

    I have plowed through the DC trying to find out how to do something like this, and although I discovered a lot of neat things you can do involving functions with Mathematica, I could not find how to do something as simple as this.

    Thanks for any help!

    James
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Sep 2010
    Posts
    185
    Thanks
    13

    Re: Mathematica discrete functions

    You are talking about piecewise defined functions - so use
    Code:
    Piecewise[definition,condition]
    .
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Apr 2012
    From
    us
    Posts
    9
    Thanks
    2

    Re: Mathematica discrete functions

    In[1]:= f[x_]:=Which[x===a,1,x===b,Pi,x===c,2,x===d,9];f[d]

    Out[2]= 9

    In[3]:= A={a,b,c,d};B={1,Pi,2,9};f[x_]:=x/.Thread[Rule[A,B]];f[d]

    Out[5]= 9
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. functions Discrete math
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: September 25th 2010, 02:13 PM
  2. Mathematica and Discrete Fourier Transforms
    Posted in the Math Software Forum
    Replies: 0
    Last Post: May 10th 2010, 09:12 AM
  3. Need Help in Functions (Discrete Math.)
    Posted in the Discrete Math Forum
    Replies: 6
    Last Post: January 31st 2010, 01:09 PM
  4. Definin recursive functions in Mathematica
    Posted in the Math Software Forum
    Replies: 5
    Last Post: January 19th 2010, 11:42 AM
  5. discrete math functions
    Posted in the Discrete Math Forum
    Replies: 8
    Last Post: June 27th 2008, 09:56 PM

Search Tags


/mathhelpforum @mathhelpforum