4
$\begingroup$

How do I create an animation that plots the following two functions? Let x vary from 0 to 15, set the y-values to range from -90 to 90 and include the fill between them. Do not include the axes in the plot. f(x) = x^2 - a*x + 20 + a where a varies from 10 to 15. g(x) = -x^2 + bx + b where b varies from 15 to 10.

I've tried Manipulate[ Plot[f[x, a], g[x, b], {x, 0, 15}], {a, 10, 15}, {b, 15, 10}], but that doesn't work.

$\endgroup$
5
$\begingroup$

You call f and g with two arguments, but they are only defined for a single argument. After fixing several typos, this seems to work:

f[x_, a_] := x^2 - a x + 20 + a;
g[x_, b_] := -x^2 + b x + b;
Manipulate[
 Plot[Evaluate[{f[x, a], g[x, b]}], {x, 0, 15}],
 {a, 10, 15}, {b, 10, 15}
 ]
$\endgroup$
  • 1
    $\begingroup$ Nice answer! You can also keep the axes from moving with PlotRange->{-100,100} within Plot. $\endgroup$ – mjw Feb 24 at 18:41
  • 1
    $\begingroup$ With Filling and other items: Manipulate[ Plot[ {f[x, a], g[x, b]}, {x, 0, 15}, Axes -> False, PlotRange -> {-90, 90}, Filling -> {1 -> {2}}, PlotLegends -> Placed[{f[x, a], g[x, b]}, {0.2, 0.15}]], {a, 10, 15, 0.1}, {b, 15, 10, -0.1}, AutoAction -> True] $\endgroup$ – Bob Hanlon Feb 24 at 18:50
  • $\begingroup$ Thank you so much guys :) $\endgroup$ – Claire Jin Feb 25 at 17:36
  • $\begingroup$ You're welcome. $\endgroup$ – Henrik Schumacher Feb 25 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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