# How do you use functions inside a Manipulate?

While modeling a falling object, the following code works fine:

h[t_] = 10 - g*t^2/2;

Manipulate[
Graphics3D[{Blue, Sphere[{0, 0, h[t]}, 2]} {t, 0, 6}]


But if I try to define a center like:

h[t_] = 10 - g*t^2/2;
center = {0, 0, h[t]}
Manipulate[
Graphics3D[{Blue, Sphere[center, 2]} {t, 0, 6}]


It throws the error:

Coordinate {0, 0, 10 - 4.905 \$CellContextt^2} should be a triple of numbers, or a Scaled form.


What is going on?

I fixed the syntax errors and added definition. This works

g = 9.81;
h[t_] := 10 - g*t^2/2;
center[t_] := {0, 0, h[t]};
Manipulate[
Graphics3D[{Blue, Sphere[center[t], 2]}, Axes -> True], {t, 0, 6},
TrackedSymbols :> {t}
]


Now center is used since it depends on t and Manipulate tracks t

• It's also a good idea to add the setting SaveDefinitions -> True` in situations like this. Apr 18, 2020 at 5:22
• @J.M. yes, But myself, I do not write things like the above. I would put all functions needed by Manipulate in its Initialization section. Apr 18, 2020 at 5:24
• Yes, I agree that's even better practice. Apr 18, 2020 at 5:27
• It's clear now. What do you mean by "put all functions needed by Manipulate in its Initialization section". Apr 18, 2020 at 17:28
• @Chegon it is like this Initialization where functions used by Manipulate are put inside Manipulate initialization section. Apr 18, 2020 at 19:19