1

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?

C. E.
  • 70,533
  • 6
  • 140
  • 264
  • 5
    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}] – Akku14 Jan 31 '21 at 05:54
  • @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. – C. E. Jan 31 '21 at 13:50
  • 1
    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. " – xzczd Jan 31 '21 at 13:54
  • @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}]`

    – ExactPlace441 Feb 26 '21 at 19:11

0 Answers0