2
$\begingroup$

I really new to Mathematica and I am working on developing interactive CDF. To understand the basics I start with a simple example but even with that I have a problem. In this simple CDF I want to able enter a function (Sin, Cos...) This is the example that I started from

Panel[DynamicModule[{f = Sin[ x]}, 
  Column[{InputField[Dynamic[f]], Dynamic[Plot[f, {x, -5, 5}]]}]]]

But here I would like to be able not only change the function also the range and one more parameter such as frequency. So I know I need to use manipulate (I want to use as CDF)

Manipulate[
 DynamicModule[{f = Sin[o x + p]}, 
  Column[{InputField[Dynamic[f]], Dynamic[Plot[f, {x, -5, 5}]]}]], {o,
   1, 10}, { p, 2, 10}]

but here I can't change the function even I type Cos and slide the o or p it goes back to Sin.

Any idea how I can do this? Also what does Column function's purpose in here?

$\endgroup$
1
  • $\begingroup$ To answer your last question, Column just places the InputField above the plot. $\endgroup$
    – Jason B.
    Apr 15, 2016 at 8:31

3 Answers 3

2
$\begingroup$

Hope I understood your question correctly. I might require to modify the code if I misinterpreted your OP.

Example:

Manipulate[
 Plot[f[x], {x, min, max}],
 {{f, Sin, "Function"}, {Sin, Cos, Tan}},
 {{min, 0, "Min."}, 0, 2 Pi},
 {{max, 2 Pi, "Min."}, 0, 2 Pi}
 ]

Output:

output example

$\endgroup$
2
$\begingroup$

Here's another simple modification of your code that allows you to specify the function,

Manipulate[
 DynamicModule[{f = Sin}, 
  Column[{InputField[Dynamic[f]], 
    Dynamic[Plot[f[o x + p], {x, -5, 5}]]}]], {o, 1, 10}, {p, 2, 10}]

enter image description here

Now you can change Sin to any built-in function that takes a single argument,

enter image description here

and still modify o and p. You can even enter a pure function. Here I'll use Function[x, x^2 - 3 x^3], and the plot will be of (o x + p)^2 - 3 (o x + p)^3

enter image description here

$\endgroup$
3
  • $\begingroup$ I like this implementation +1 $\endgroup$ Apr 15, 2016 at 8:38
  • $\begingroup$ I am trying to carry this one more step further. I changed the idea from plot to take an integral. $\endgroup$
    – Erdem
    Apr 20, 2016 at 12:33
  • $\begingroup$ @Erdem, the basic idea should be the same. $\endgroup$
    – Jason B.
    Apr 20, 2016 at 12:35
0
$\begingroup$

this is an answer also a question at the same time. I am simply trying to avoid using sliders and predefined functions to increase the capacity of the CDF file. I changed my example to taking integral and use inputfield for the function and upper and lower limit. It completely functional but not best presentation and controls. Here is the code

Manipulate[Panel[DynamicModule[{f = Sin[x], xR = 1, xL = 0},   Column[{InputField[Dynamic[xL]], InputField[Dynamic[xR]], 
 InputField[Dynamic[f]], Dynamic[NumberForm[NIntegrate[f, {x, xL, xR}, WorkingPrecision -> nw], np]]}]]],{{np, 10, "NumberFormat"}, 10, 30, 1}, {{nw, 16, "WorkingPrecision"}, 10, 30,1}]

I have 3 input fields, Lower Limit, Upper Limit, and the Function

  • First of all I would like to be able to insert name tags above or on the right of these fields.
  • Second I would like to have a box for the result
  • I would like to be able limit the input for lower and upper limit to numbers and incase user inputs a character gives an warning message.

For name tags I tried using FieldHint command but it did not work because I think I had to predefine a value for xL and xR and f.

Any ideas are welcome not only the answers I am looking for.

Thanks

$\endgroup$

Your Answer

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

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