3
$\begingroup$

I'm trying to generate this simple graph using the Manipulate function

f[x_] := a x + b x^2;
Manipulate[Plot[f[x], {x, 0, 1}], {a, 0, 1}, {b, 0, 1}]

However, Mathematica doesn't return any graph! If instead of the above, I use now

Manipulate[Plot[a x + b x^2, {x, 0, 1}], {a, 0, 1}, {b, 0, 1}]

I can get what I wanted. Any thoughs on why the manipulate doesn't work with functions? Thanks!

$\endgroup$
  • $\begingroup$ This is covered in the "Possible Issues" section of the documentation for Manipulate. See example after Manipulate only "notices" explicit visible parameters $\endgroup$ – Bob Hanlon Jun 30 at 2:02
7
$\begingroup$

The problem is that you must pass a and b to the function. Try f[3] with your current definition and you get 3a + 9b which cannot be plotted. When using SetDelayed (:=), it cannot see that there is an a and b inside the function so it does not know where to assign the values. Instead, try this:

f[x_, a_, b_] := a x + b x^2
Manipulate[Plot[f[x, a, b], {x, 0, 1}], {a, 0, 1}, {b, 0, 1}]

Image of Manipulate

| improve this answer | |
$\endgroup$

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