1
$\begingroup$

I want to be able to Dynamically Plot functions with parameters. One should be able to change the parameter and the function, while the function field should accept the parameter and the variable, which we set to x.

I know that one can plot any function... but when I try to include the parameter:

Panel[DynamicModule[{a = 2, f = Cos[a*x]}, Column[{InputField[Dynamic[a], ContinuousAction -> True], 
InputField[Dynamic[f]], Dynamic[Plot[f, {x, -5, 5}]]}]]]

things do not seem to work as expected. When I change the parameter, the plot, nor the function field gets updated, but when I change the function, the plot updates. If use the parameter a in the input field of the function, the everything breaks.

$\endgroup$
1
  • $\begingroup$ The question is unclear. What do you mean by "If use the parameter a in the input field of the function, the everything breaks"? Do you mean that, when you e.g. change Cos[2 x] in the second InputField to Cos[234 x], you want the 2 in the first InputField be updated to 234? If so, what's the expected behavior if you've inputted e.g. Cos[4 x^2+5 x^3] in the second InputField? Please clarify, the question will be reopened once it meets the standard of the site. $\endgroup$ Commented Jan 22 at 1:25

1 Answer 1

1
$\begingroup$
Manipulate[
  Plot[f[a*x], {x, -5, 5}, PlotLabel -> "f[a*x]"],
  {{f, Cos}, {Sin, Cos}},
  {{a, 1}, -5, 5, .25}]

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.