5
$\begingroup$

I've been playing around with dynamic input fields; here's a basic example, which just consists of an input field where the user can enter a function and then a button that can be clicked to graph the function. What I'm wondering is: is there a way to allow free-form linguistic input to be entered in the input field? Right now, I must enter regular Mathematica syntax like Cos[x] to get a graph, but I'd really like to be able to enter something like "cos x". (Ultimately, I'd like my dynamic module to do more than just graph the function, which is why I don't want to just use Wolfram Alpha directly.)

DynamicModule[{graph, f, button},
 graph = Plot[1, {x, 0, 1}, PlotRange -> {0, 0.1}, Axes -> False, 
   ImageSize -> 480, Background -> White];
 f = Cos[x];

 button = Button["Graph!",
   graph = Plot[f, {x, -3, 3}, ImageSize -> 480, Background -> White];
   ];

 Panel[
  Grid[{
    {InputField[Dynamic[f]], button},
    {Dynamic[graph], SpanFromLeft}},
   Spacings -> {2, 1}, Alignment -> {Left, Baseline}
   ]
  ]
 ]

Thanks!

$\endgroup$

1 Answer 1

7
$\begingroup$

I believe that Mathematica feeds the input string in free-form linguistic input to the function WolframAlpha. Try something like

Manipulate[
 If[in =!= "", WolframAlpha[in], "Enter input"],
 {{in, ""}, InputField[Dynamic[in], String] &}
 ]

Manipulate output


Response to comment

I can't find a definitive statement in the documentation that an internet connection is required for all free-form linguistic input, but the following suggests that it is (just as I thought, too).

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Thanks, this helps. I really just want the input form of the function, and it looks like I can get it by doing something like WolframAlpha[f, {{"Input", 1}, "Input"}] This is a separate question, but does all of the free-form linguistic input require an internet connection? I see that the WolframAlpha command certainly does, and ideally I'd use something that worked offline as well. $\endgroup$
    – Janet
    Commented Oct 10, 2013 at 23:56
  • $\begingroup$ @Janet I believe an internet connection is required. See update. $\endgroup$
    – Michael E2
    Commented Oct 11, 2013 at 0:20
  • $\begingroup$ Thanks! The same thing happens when I try it offline, so that must just be how it is. $\endgroup$
    – Janet
    Commented Oct 11, 2013 at 1: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.