What does f[a] mean in mathematica?

In summary, f[a] in Mathematica represents a function with an argument of a. It can be used to define specific functions or evaluate expressions with specific values for the argument a. It can also have multiple arguments separated by commas. However, it is different from f(a) in other programming languages, as the square brackets indicate a function with an argument in Mathematica. To assign a value to f[a], the Set (=) or SetDelayed (:=) operators can be used.
  • #1
tgt
522
2
What does f[a] mean in mathematica?

What does f[a] mean in mathematica?
 
Physics news on Phys.org
  • #2


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


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


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


CompuChip said:
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?


That's right. How to do it?
 
Last edited:
  • #6


So the simplest form is
Code:
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:
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


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

[/QUOTE]

why g?
 
  • #8


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.
 

1. What does f[a] mean in Mathematica?

In Mathematica, f[a] represents a function called f with an argument of a. This means that when a value is assigned to the variable a, it will be substituted into the function f to evaluate the expression.

2. How is f[a] used in Mathematica?

f[a] is commonly used in Mathematica to represent a general function with a variable argument. It can also be used to define specific functions or to evaluate expressions with specific values for the argument a.

3. Can f[a] have multiple arguments in Mathematica?

Yes, f[a] can have multiple arguments in Mathematica. These arguments can be separated by commas, and the function will evaluate the expression for each argument provided.

4. Is f[a] the same as f(a) in other programming languages?

No, f[a] in Mathematica is not the same as f(a) in other programming languages. In Mathematica, the square brackets indicate a function with an argument, while parentheses are used for grouping and other purposes.

5. How do I assign a value to f[a] in Mathematica?

To assign a value to f[a] in Mathematica, you can use the Set (=) or SetDelayed (:=) operators. For example, f[a_]:= a^2 will assign the value of a^2 to f[a]. You can then use this function to evaluate expressions with specific values for a.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
395
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
211
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
240
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
554
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top