What does f[a] mean in mathematica?

1. Nov 18, 2008

tgt

What does f[a] mean in mathematica?

What does f[a] mean in mathematica?

2. Nov 18, 2008

CompuChip

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]

3. Nov 18, 2008

tgt

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?

4. Nov 18, 2008

CompuChip

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 ...

5. Nov 18, 2008

tgt

Re: mathematica

That's right. How to do it?

Last edited: Nov 18, 2008
6. Nov 19, 2008

CompuChip

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.

7. Nov 19, 2008

tgt

Re: mathematica

8. Nov 20, 2008

CompuChip

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.