1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What does f[a] mean in mathematica?

  1. Nov 18, 2008 #1

    tgt

    User Avatar

    What does f[a] mean in mathematica?

    What does f[a] mean in mathematica?
     
  2. jcsd
  3. Nov 18, 2008 #2

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Re: mathematica

    It applies a to the function f, and then b to the resulting function.
    For example, you could do something like
    f[a_] := (a + #)&
    then
    f[3] would give the function (3 + #)& and applying that to 2 would produce 5.

    In more extended notation,
    f[a_] := Function[y, a + y]
    f[3] => Function[y, 3 + y]
    f[3][2] = Function[y, 3 + y][2] = 3 + 2 = 5

    Or, equivalently
    f[a_, b_] := a + b
    f[3, 2]
     
  4. Nov 18, 2008 #3

    tgt

    User Avatar

    Re: mathematica

    So F[a]=F[a,b]?

    What happens if I'd like F[x] to be indexed by i=1,2,3,...

    how to do that?
     
  5. Nov 18, 2008 #4

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Re: mathematica

    No, F[a] is F[a] applied to b, which is (f applied to a) applied to b.
    It depends on what F is.

    How do you mean "indexed" by i = 1, 2, 3? You would like three functions F[x], G[x], H[x] but call them Fi[x] (i = 1, 2, 3) instead? Or ...
     
  6. Nov 18, 2008 #5

    tgt

    User Avatar

    Re: mathematica


    That's right. How to do it?
     
    Last edited: Nov 18, 2008
  7. Nov 19, 2008 #6

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Re: mathematica

    So the simplest form is
    Code (Text):
    Subscript[g, 1][x_] := x
    Subscript[g, 2][x_] := x^2
    Subscript[g, 3][x_] := Sin[x]

    Plot[{Subscript[g, 1][x], Subscript[g, 2][x],
      Subscript[g, 3][x]}, {x, -1, 1}]
    where you can type g2 using Control + hyphen (-).

    An alternative would be
    Code (Text):
    Subscript[f, i_?(Function[IntegerQ[#] && 1 <= # <= 3])][x_] :=
     Which[i == 1, F[x], i == 2, G[x], i == 3, H[x], True, "This should not occur!"]
    Then you can call fi[x] (type with Control + - (hyphen)) for i = 1, 2, 3 and it will call F[x], G[x] or H[x], respectively. The complicated-looking pattern matching is to have it return just fi[x] if i is not 1, 2 or 3.
     
  8. Nov 19, 2008 #7

    tgt

    User Avatar

    Re: mathematica

     
  9. Nov 20, 2008 #8

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Re: mathematica

    Why not?
    I had already used f in the other example. You can call it f if you want, or Apples, or GqoFKdsJF or LoremIpsumDolorem. Just don't use any reserved names (E, N, Sin, ...) or - preferably - things you already defined.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: What does f[a] mean in mathematica?
Loading...