       Wrapping NDSolve within a function

• To: mathgroup at smc.vnet.net
• Subject: [mg126337] Wrapping NDSolve within a function
• From: bbeckage <Brian.Beckage at uvm.edu>
• Date: Wed, 2 May 2012 05:44:45 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```When I try to return the interpolating function produced by NDSolve from
within a function, the object returned has an unexpected \$7360 appended,
e.g.,

out = predState[1.5, 0.4, 0.2, 0.1, 0.0002, 0.0099]

(where predState is defined further below) results in

=
{{g\$7360->InterpolatingFunction[{{0.,1000.}},<>],p\$7360->InterpolatingFunction[{{0.,1000.}},<>],q\$7360->InterpolatingFunction[{{0.,1000.}},<>]}}

Note the g\$7360 rather than just g.  If NDSolve is not wrapped within
the function, it returns a plain 'g', i.e., g->InterpolatingFunction....
The appended \$7360 makes it difficult to use the interpolating function
as I can't reference it within other functions as the integer changes
with each function call, e.g., g\$7360 /. out, then g\$7370 /.
out, rather than being able to access it using the expected g/.out.

Why  is this \$7360 appended to g?  How can NDSolve be wrapped in a
function, but be made to return a plain g?

Best wishes,
Brian

predState[rg_, rp_, rh_, Mg_, Mp_, Mh_] :=
Module[{parmList3woC, parmListND3woC, A, B, Rb, Rc, g, p, q, solND},
parmListND3woC = {A -> Mg/rg, B -> Mp/rg, C -> Mh/rg, Rb -> rp/rg,
Rc -> rh/rg};
solND =
NDSolve[{
g'[t] == g[t]*(1 - g[t] - p[t] - q[t]) - A*g[t]*g[t] /. parmListND3woC,
p'[t] == Rb*p[t]*(1 - p[t] - q[t]) - B*p[t]*g[t] /. parmListND3woC,
q'[t] == Rc*q[t]*(1 - q[t]) - C*q[t]*g[t] /. parmListND3woC, g == 0.5,
p == 0.5, q == 0.5}, {g, p, q}, {t, 0, 1000}];
Return[solND]
]

```

• Prev by Date: Re: Integration bug? Integrate[Sin[2 t]^2 Cos[Cos[t - p]], {t, 0, 2 Pi}]
• Next by Date: Re: Struggling to prove simple triangle inequality
• Previous by thread: Re: Integration bug? Integrate[Sin[2 t]^2 Cos[Cos[t - p]], {t, 0, 2 Pi}]
• Next by thread: Re: Wrapping NDSolve within a function