1
$\begingroup$

I am trying to write code to animate a resonance curve so that I can visualize changes in a parameter. However, even though my Plot[] plots values, my Animate[Plot[]] does not. I am unsure why.

resAmpEqn = a^2 == (f)^2 / (((res)^2 - w^2)^2 + 4 b^2 w^2);

Plot[resAmpEqn[[2]] /. {f -> 1, res -> 10, b -> 1}, {w, 0, 20}, 
 PlotRange -> Full]

Animate[Plot[resAmpEqn[[2]] /. {f -> 1, res -> 10}, {w, 0, 20}, 
  PlotRange -> Full], {b, 0.5, 1.5}]

enter image description here

Does anyone here know why?

$\endgroup$
4
  • 5
    $\begingroup$ Because the variable b in Animate is regarded only local. You have to give over the global b to the local b of Animate. Define resAmpEqn[b_] = ..... and use Animate[Plot[resAmpEqn[b][[2]] /. {f -> 1, res -> 10}, {w, 0, 20}, PlotRange -> Full], {b, 0.5, 1.5}] or the dirty variant Animate[Plot[ resAmpEqn[[2]] /. {f -> 1, res -> 10, b -> bb}, {w, 0, 20}, PlotRange -> Full], {bb, 0.5, 1.5}] $\endgroup$
    – Akku14
    Commented Jan 31, 2021 at 5:54
  • $\begingroup$ @Akku14 It would be great if you posted that as an answer, so the question won't appear to be unanswered even though you have answered it. $\endgroup$
    – C. E.
    Commented Jan 31, 2021 at 13:50
  • 1
    $\begingroup$ Does this answer your question? Simple problem with Manipulate and Plot Notice that, as mentioned in Details and Options section of document of Animate, "Animate generates a Manipulate object containing an Animator. " $\endgroup$
    – xzczd
    Commented Jan 31, 2021 at 13:54
  • $\begingroup$ @Akku14 Very sorry for the delay. When I implement this, I get an error: "Tag Times in ((f^2)/(1.\w^2+(res^2-w^2)^2))[b_] is Protected" Code I implemented: resAmpEqn[b_] = (f)^2/(((res)^2 - w^2)^2 + 4 b^2 w^2) Animate[Plot[resAmpEqn[b][[2]] /. {f -> 1, res -> 10}, {w, 0, 20}, PlotRange -> Full], {b, 0.5, 1.5}] $\endgroup$ Commented Feb 26, 2021 at 19:11

0

Browse other questions tagged or ask your own question.