# Animate cannot use functions

**URL:** <https://community.wolfram.com/t/animate-cannot-use-functions/2022>\
**Category:** Questions\
**Tags:** mathematica, graphics-and-visualization, interface-construction\
**Created:** [April 21, 2014, 3:18am UTC](https://community.wolfram.com/t/animate-cannot-use-functions/2022 "2014-04-21T03:18:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhoulihan](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@bhoulihan](https://community.wolfram.com/u/bhoulihan)\
**Post date:** [April 21, 2014, 3:18am UTC](https://community.wolfram.com/t/animate-cannot-use-functions/2022/1 "2014-04-21T03:18:12Z")

</div>

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:

```auto
Animate[Plot[4 x^2 + a x^3 + 5 x, {x, -5, 5}], {a, -1, 1}]

```

But this does not work:

```auto
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?

---

<div class="post-metadata">

**Author:** ![halemichaeljr](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/halemichaeljr/32/22773_2.png) [@halemichaeljr](https://community.wolfram.com/u/halemichaeljr)\
**Post date:** [April 21, 2014, 3:26am UTC](https://community.wolfram.com/t/animate-cannot-use-functions/2022/2 "2014-04-21T03:26:42Z")

</div>

Hi Bruce,

The “a” inside of Animate is a [local variable](http://reference.wolfram.com/mathematica/tutorial/ModulesAndLocalVariables.html), 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.

```auto
p[z_, a_] := 4 z^2 + a z^3 + 5 z; Animate[
 Plot[p[x, a], {x, -5, 5}], {a, -1, 1}]

```

---

<div class="post-metadata">

**Author:** ![dreiss](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/dreiss/32/29094_2.png) [@dreiss](https://community.wolfram.com/u/dreiss)\
**Post date:** [April 21, 2014, 3:27am UTC](https://community.wolfram.com/t/animate-cannot-use-functions/2022/3 "2014-04-21T03:27:40Z")

</div>

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** )

```auto
p[z_, a_] := 4 z^2 + a z^3 + 5 z;

Animate[Plot[p[x, a], {x, -5, 5}], {a, -1, 1}]

```

---

<div class="post-metadata">

**Author:** ![bhoulihan](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@bhoulihan](https://community.wolfram.com/u/bhoulihan)\
**Post date:** [April 22, 2014, 4:51pm UTC](https://community.wolfram.com/t/animate-cannot-use-functions/2022/4 "2014-04-22T16:51:04Z")

</div>

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.
