Definition function with variable in name

In summary, the conversation is about creating functions in a loop using the Table function and naming them based on a numerical step. The solution is to use f[i]=Interpolation[data] and for specifying a variable, f[i][x_]:=... should be used instead of f[x_]=... which is not recommended.
  • #1
Vrbic
407
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
  • #2
Just use f[1]=Interpolation[data1] etc.
 
  • #3
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.
 
  • #4
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:
  • #5
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.
 

What is a "Definition function with variable in name"?

A definition function with variable in name refers to a function in a programming language that takes in a variable as one of its parameters. This allows the function to perform different calculations or operations depending on the value of the variable.

How do you create a definition function with variable in name?

To create a definition function with variable in name, you first need to define the function with the keyword "def" followed by the function name and parentheses. Inside the parentheses, you can specify the variable name as one of the parameters. You can then use the variable in your function code to perform different operations.

What is the purpose of using a variable in a definition function?

Using a variable in a definition function allows for more flexibility and reusability in your code. By passing in different values for the variable, the function can produce different results, making it more versatile and efficient.

Can a definition function have multiple variables in its name?

Yes, a definition function can have multiple variables in its name. This is useful for functions that require multiple inputs to perform their intended operations.

What is the difference between a variable and a parameter in a definition function?

A variable is a placeholder for a value that can change, while a parameter is a variable that is defined when the function is created and is used to pass in values when the function is called. Parameters are essentially variables that are specific to a particular function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
415
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
934
  • Programming and Computer Science
Replies
3
Views
357
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
930
Replies
7
Views
823
  • Set Theory, Logic, Probability, Statistics
Replies
30
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top