1
$\begingroup$

I need to ask the user the function to make some procedures. For example, instead of having at the code

f[x_] := Sqrt[1 + x]; 

and then

f[5]

I need to do something like this:

userFunction = Input["Type your function"]
f[x_] := userFunction;

Of course the user should type a valid function, like Sqrt[x], but it´s not working.

$\endgroup$

1 Answer 1

1
$\begingroup$
 userFunction = Input["Type your function"]

Mathematica graphics

 f[x_] := Evaluate@userFunction;
 f[5]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Great, it works! Edit, I've tried with other results and the decimals are the same. Thanks a lot! $\endgroup$ Feb 22, 2020 at 18:57
  • $\begingroup$ It works the same for me. Here is screen shot !Mathematica graphics Are you typing Log2[x] and adding "" around it? That will make it string. Just type Log2[x] in the input box, without double quotes. $\endgroup$
    – Nasser
    Feb 22, 2020 at 19:01
  • $\begingroup$ Already checked and solved the problem, it was a factor method, at decimals it was the same. Again, thanks a lot! $\endgroup$ Feb 22, 2020 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.