MathGroup Archive 2009

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96252] Re: newbie: explicit function works, "function object" doesn't
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Tue, 10 Feb 2009 05:51:36 -0500 (EST)
  • References: <gmp0st$c30$1@smc.vnet.net>

Hi Tom,

The answer to your question lies deeply hidden in the "Possible
Issues" section of the Manipulate documentation. There one finds:

"Manipulate only "notices" explicit visible parameters"

What you put in your Manipulate (theta[t] /. First[soln]) visibly
depends on t only and not on omega, V0, and theta0.

Rewriting your code as:

linearPendulum = {theta''[t] == -omega^2 theta[t]};
theta'[0] == v0;
theta[0] == theta0;
soln = DSolve[{linearPendulum, theta'[0] == v0, theta[0] == theta=
0},
   theta[t], t];
sol[omega_, theta0_, v0_, t_] = theta[t] /. First[soln];
Manipulate[
 Plot[sol[omega, theta0, v0, t], {t, -2 Pi, 2 Pi}],
 {{omega, 1}, 0, 5}, {{theta0, 1}, 0, 5}, {{v0, 1}, 0, 5}]

makes it work.

Note that I moved the whole definition part out of Manipulate as it
needs to be defined only once.

Cheers -- Sjoerd

On Feb 9, 12:35 pm, Tom Roche <tlro... at gmail.com> wrote:
> 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.
>
> details:
>
> 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 @
>
> http://www.unc.edu/~tr/classes/GEOL861/hw1Notebook.nb
>
> I'm trying initially to model a linearized pendulum
>
> theta''[t] == -omega^2 theta[t]
>
> (where omega=g/l) with the simple initial conditions
>
> theta'[0]==v0
> theta[0]==theta0
>
> Using
>
> soln = DSolve[{linearPendulum, theta'[0] == v0, theta[0] == the=
ta0},
> 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_Ro... at pobox.com>



  • Prev by Date: Re: newbie: explicit function works, "function object"
  • Next by Date: Re: "mapping" functions over lists, again!
  • Previous by thread: Re: newbie: explicit function works, "function object" doesn't
  • Next by thread: Re: newbie: explicit function works, "function object" doesn't