Mathematica Definition function with variable in name

AI Thread Summary
The discussion centers on creating functions in a loop with variable names based on an index, specifically using interpolation for different datasets. The initial query seeks advice on defining functions with names that include a step number, such as f"i". A suggested solution is to use f[i] = Interpolation[data1], which is well-received. Further, the user inquires about specifying a variable within the function, initially attempting f[x_] = ..., which is noted as ineffective. The recommended approach involves using a delayed set with f[i][x_] := ..., although it is advised to use an immediate set for the function name only. The user confirms success with the provided solutions, expressing gratitude for the assistance.
Vrbic
Messages
400
Reaction score
18
Hello,
I would like to create few functions in loop by Table (not ordinary change a parameter, but different numerical solution of problem). The names should differ by "number"of the step, let's say "i", in the name. I.e. I would like to get set of function f"i"={f1=Interpolation[data], f2=Interpolation[data1],...}
Can you advise me how to write the definition of function with variable "i" in name?

Thank you for a help.
 
Physics news on Phys.org
Just use f[1]=Interpolation[data1] etc.
 
Dale said:
Just use f[1]=Interpolation[data1] etc.
Thank you, very clever solution :-)
And just hypothetically, if I would like to specify a variable of the function. I tried f[x_]=..., but it doesn't work.
 
Vrbic said:
Thank you, very clever solution :-)
And just hypothetically, if I would like to specify a variable of the function. I tried f[x_]=..., but it doesn't work.
You would need to use delayed set for that
Code:
 f[i][x_]:= ...

But I wouldn't recommend that. I would use immediate set on the function name only
 
Last edited:
Dale said:
You would need to use delayed set for that
Code:
 f[i][x_]:= ...

But I wouldn't recommend that. I would use immediate set on the function name only
Haaa it works :-)
Thank you very much.
 

Similar threads

Replies
4
Views
3K
Replies
5
Views
2K
Replies
4
Views
1K
Replies
0
Views
553
Replies
3
Views
2K
Replies
1
Views
4K
Replies
13
Views
2K
Back
Top