I need to make a Module whose input is a function of 2 variables and 2 variables m,n so i can make a Matrix with Array. Basicaly, I need this:
f[x_, y_] = Input[]
M = Array[f, {m,n}]
MatrixForm[M]
to make it work in a Module.
I need to make a Module whose input is a function of 2 variables and 2 variables m,n so i can make a Matrix with Array. Basicaly, I need this:
f[x_, y_] = Input[]
M = Array[f, {m,n}]
MatrixForm[M]
to make it work in a Module.
Would something like this work for you?
generatematrix :=
Module[
{rows, columns, function, result},
rows = Input["Enter the number of rows"];
columns = Input["Enter the number of column"];
function = Input["Enter the function"];
result = Array[function, {rows, columns}];
MatrixForm@ result
]
Every time you evaluate generatematrix, three input dialogs will pop up, asking for the value of the first variable, the second variable, and then for the function you want to use. So for instance, if one entered 2, 3, and f in the three dialogs, the output would be:

I'd like to point out something, though, regarding the fact that you wanted the MatrixForm of this expression returned. As you may be aware, MatrixForm is an output wrapper that may get in the way of further calculations carried out on your output matrix. It may be safer to return a plain output format (i.e. list of lists), and do the formatting outside of the function:
generatematrixNoMatrixForm :=
Module[
{rows, columns, function, result},
rows = Input["Enter the number of rows"];
columns = Input["Enter the number of column"];
function = Input["Enter the function"];
Array[function, {rows, columns}]
]
MatrixForm@ generatematrixNoMatrixForm
MatrixForm, and the one without.
– MarcoB
May 20 '15 at 23:20