MathGroup Archive 2012

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

Search the Archive

Re: Rule replacement doesn't work after NDSolve?

  • To: mathgroup at
  • Subject: [mg124013] Re: Rule replacement doesn't work after NDSolve?
  • From: A Retey <awnl at>
  • Date: Thu, 5 Jan 2012 05:59:12 -0500 (EST)
  • Delivered-to:
  • References: <je18a2$3c9$>


> Thanks very much for the reply.  Your suggestion works as you say,
> but I'm still confused.  I thought that the replacement is for the
> function, not the arguments.
>> rules must be applied before the arguments are set (as is done in
>> the plots).
> Why, then, does this work?
> sol2 = NDSolve[{y'[t] == 1/x[t]^2, x'[t] == 1/y[t], x[0] == 1, y[0]
> == 1}, {x, y}, {t, 0, 1}] y[0.5] /. sol2 x[0.5] /. sol2

because here you specified the dependent variables as {x,y}, not {x[t],y[t]}

> One difference I see is that the output in the PDE case has the
> arguments z,t on the lhs:
> {Subscript[x,
> 1][z,t]->InterpolatingFunction[{{0.,20.},{0.,10.}},<>][t,z],...

... and that's about the only difference that's relevant for all the 
following substitutions...

> But the output in the ODE case does not have the argument on the
> lhs:
> {x->InterpolatingFunction[{{0.,1.}},<>],...

it has nothing to do with PDE vs. ODE, what matters is how you specify
the dependent variables (that's the second argument to NDSolve). If you 
specify those with arguments, the results
will be given as rules with arguments. If you specify them without
arguments, then the rules will be without arguments. I think it is
generally better to specify the independent variables without arguments
which results in rules without arguments, which will behave much nicer
in all relevant circumstances that I can think of. Actually I don't see 
a good reason why the other form exists at all...

> And, if it's a matter of the order of operations, why does this
> statement also work for the ODE case:
> y[t] /. sol2 /. {t ->  0.5}

that's because sol2 does not contain arguments (it contains a rule 
y->InterpolatingFunction[<>]), so in y[t] only y is
replaced, which works for whatever argument might be given and then
after that t is replaced in InterpolatingFuntion[<>][t].

> There's an important difference between the way NDSolve returns in
> the PDE case and in the ODE case.  I'd like to better understand the
> difference.

there is absolutely no difference between the way NDSolve returns
results between PDE and ODE cases: it is only depending on how you
specify dependent variables! I think your problem is not with NDSolve 
but with how Mathematicas pattern matching and evaluator work, which I 
just can recommend to learn if you want to avoid further confusion...



  • Prev by Date: Re: Mathematica on tablet computer
  • Next by Date: Extension to BinLists Function
  • Previous by thread: Re: Rule replacement doesn't work after NDSolve?
  • Next by thread: Re: Rule replacement doesn't work after NDSolve?