MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: newbie: explicit function works, "function object" doesn't

  • To: mathgroup at
  • Subject: [mg96267] Re: [mg96207] newbie: explicit function works, "function object" doesn't
  • From: "David Park" <djmpark at>
  • Date: Tue, 10 Feb 2009 05:54:28 -0500 (EST)
  • References: <32689826.1234178726482.JavaMail.root@m02>


It is generally good practice to have ALL symbols in a function definition
be part of the definition itself and not just 'hanging loose'. This made a
difference in the Manipulate statement because the control parameters are
local variables within the Manipulate statement. That is why it would not
work for you until you put the definitions and solution inside the
Manipulate statement.

First solve the differential equation and obtain a function for theta that
contains the parameters in the definition of the function. In this case the
parameters are entered as what are called SubVaues in Mathematica. You could
remove the semicolons to see the intermediate steps.

linearPendulum = {theta''[t] == -omega^2 theta[t]};
Part[DSolve[{linearPendulum, theta'[0] == v0, theta[0] == theta0}, 
   theta, t], 1, 1];
theta[omega_, theta0_, v0_][t_] = theta[t] /. %

(omega theta0 Cos[omega t] + v0 Sin[omega t])/omega

We can see that we now have a way to express the function with any
particular set of parameters.

theta[2, 3, 1][t]
1/2 (6 Cos[2 t] + Sin[2 t])

Now the Manipulate statement is much simpler. All we need is the Plot
statement. Dynamic plots like this are much better if they are displayed
with a fixed PlotRange. However, you might want to add an additional control
to set the vertical plot range.

 Plot[theta[omega, theta0, v0][t], {t, -2 \[Pi], 2 \[Pi]},
  Frame -> True,
  AxesStyle -> LightGray,
  PlotRange -> {{-2 \[Pi], 2 \[Pi]}, {-5, 5}}],
  {{omega, 1}, 0.0001, 5, Appearance -> "Labeled"},
  {{theta0, 1}, 0, 5, Appearance -> "Labeled"},
  {{v0, 1}, 0, 5, Appearance -> "Labeled"}]

Now you should be able to do the damped oscillator.

David Park
djmpark at  

From: Tom Roche [mailto:tlroche at] 

summary: I've got a function that I can Manipulate, but I can't
Manipulate the things to which the function is assigned. I'm assuming
this is due to a syntax error.


As advertised by the Subject:, I'm new to Mathematica (specifically M7
running on a linux cluster) so please excuse any lapses in
terminology. I'd also appreciate pointers to specific docs rather than
just an RTFM. Also feel free to refer to my notebook @

I'm trying initially to model a linearized pendulum

theta''[t] == -omega^2 theta[t]

(where omega=g/l) with the simple initial conditions



soln = DSolve[{linearPendulum, theta'[0] == v0, theta[0] == theta0},
theta[t], t]

I get the solution

theta[t] -> (omega*theta0*Cos(omega*t) + (v0*Sin(omega*t)))/omega

However, when I try to Manipulate[Plot[soln...]], I get ... nothing.
Not an error, and I do get the appropriate UI, but I don't get a plot.

>From what I've read, it seems Manipulate wants an expression like the
RHS of 'soln', which I'll refer to here as a "function." (Please
correct my usage as needed.) I got a "function object" with ReplaceAll

happysoln[t_] = theta[t] /. soln[[1]]

similar to a working example I've seen. But
Manipulate[Plot[happysoln...]] also fails silently, like the previous.

However, when I manipulate the "function" directly

Manipulate[Plot[(omega theta0 Cos[omega t] + v0 Sin[omega t])/omega,
{t, -2 Pi, 2 Pi}], {{omega, 1}, 0, 5}, {{theta0, 1}, 0, 5}, {{v0, 1},
0, 5}]

it works as designed: I get the UI with the plot, which I can twiddle
with the sliders.

Why can I Manipulate the function, but not the containers of the
function (i.e. soln, happysoln)? More importantly, with what syntax
can I Manipulate those containers?

TIA, Tom Roche <Tom_Roche at>

  • Prev by Date: Re: "mapping" functions over lists, again!
  • Next by Date: Default Input and Output Format
  • Previous by thread: Re: newbie: explicit function works, "function object" doesn't
  • Next by thread: [any workaround for] very slow Save[]s on Mathematica V7??