Message Boards Message Boards

3 Replies
0 Total Likes
View groups...
Share this post:

Animate cannot use functions

Posted 10 years ago
I'm trying to animate a function with parameters, and it seems animate cannot handle a function definition, only the function description. For example, this works:
Animate[Plot[4 x^2 + a x^3 + 5 x, {x, -5, 5}], {a, -1, 1}]
But this does not work:
p[z_] := 4 z^2 + a z^3 + 5 z;
Animate[Plot[p[x], {x, -5, 5}], {a, -1, 1}]
and just gives a blank plot with no graph. Is Animate unable to handle functions?
3 Replies
Posted 10 years ago
Hi Bruce,

The "a" inside of Animate is a local variable, and it is not the same as the global "a" that appears in your function. You can pass the local "a" from the Animate into your function as a second argument.
p[z_, a_] := 4 z^2 + a z^3 + 5 z; Animate[
Plot[p[x, a], {x, -5, 5}], {a, -1, 1}]
POSTED BY: Michael Hale
If I understand correctly what you are trying to write, your first argument ot the Plot function is not calling your funciton p with any arguments.  Also your function p is not explicitly a function of a.

Is this what you actually mean? (note the semicolon and the first argument of Plot)
p[z_, a_] := 4 z^2 + a z^3 + 5 z;

Animate[Plot[p[x, a], {x, -5, 5}], {a, -1, 1}]
POSTED BY: David Reiss
Posted 10 years ago
Making a an argument of the function fixed the problem in the Animate, appreciated. Had no idea there were "local" and "global" concepts in the function definitions.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract