Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7562 > unrolled thread

Re: Rule replacement doesn't work after NDSolve?

Started bygac <g.crlsn@gmail.com>
First post2012-01-04 10:05 +0000
Last post2012-01-05 11:01 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Rule replacement doesn't work after NDSolve? gac <g.crlsn@gmail.com> - 2012-01-04 10:05 +0000
    Re: Rule replacement doesn't work after NDSolve? A Retey <awnl@gmx-topmail.de> - 2012-01-05 11:01 +0000

#7562 — Re: Rule replacement doesn't work after NDSolve?

Fromgac <g.crlsn@gmail.com>
Date2012-01-04 10:05 +0000
SubjectRe: Rule replacement doesn't work after NDSolve?
Message-ID<je18a2$3c9$1@smc.vnet.net>
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

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],...

But the output in the ODE case does not have the argument on the lhs:

{x->InterpolatingFunction[{{0.,1.}},<>],...

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}

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.

Thanks again for the solution.

Regards.

[toc] | [next] | [standalone]


#7590

FromA Retey <awnl@gmx-topmail.de>
Date2012-01-05 11:01 +0000
Message-ID<je3vuh$een$1@smc.vnet.net>
In reply to#7562
Hi,

> 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...

hth,

albert

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web