I'm looking for a way to build a function from an input string in a text box for use in graphics. This is the indended functionality:
DynamicModule[
{f = "x^2 + Sin[y]", x, y},
Column[{
Row[{"f(x,y)=", InputField[Dynamic[f]]}],
Row[{"f= ", Dynamic[f]}],
Plot3D[ToExpression[f][x, y], {x, 0, 1}, {y, 0, 1}]
}]
]
Notably, I'd like to support any form (not strictly c₁·x² + c₂·Sin[y]) and a variable number of arguments (though I'll need to know how many arguments when I try to plot it).
I've tried some approaches using ToExpression and Symbol with no luck. I did manage to define a function inside the inputbox, ie:
f[x_]:=x^2; {ENTER}
f[3] {ENTER}
↳ Modifies the inputbox to display 9, but I can't seem to extract that f[] that I defined.
I also tried to modify the code in this answer, but I still couldn't get the expression to be stored as a function like the asker requested there.
Am I missing something, or is this behavior not really possible in Mathematica?