Re: Rule replacement doesn't work after NDSolve?
- To: mathgroup at smc.vnet.net
- Subject: [mg124007] Re: Rule replacement doesn't work after NDSolve?
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Thu, 5 Jan 2012 05:57:07 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201201041003.FAA03397@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
There's nothing mysterious going on. For instance, sol2 = NDSolve[{y'[t] == 1/x[t]^2, x'[t] == 1/y[t], x[0] == 1, y[0] == 1}, {x, y}, {t, 0, 1}] {x[0.5], y[0.5]} % /. sol2 {{x->InterpolatingFunction[{{0.,1.}},<>],y->InterpolatingFunction[{{0.,1.}},<>]}} (* sol2 *) {x[0.5], y[0.5]} (* x and y are unknown *) {{1.42211, 1.34557}} (* sol2's left hand sides -- x and y -- are present in {x[0.5], y[0.5]}, so Replace can replace them *) In your original code, what did NOT work came about when this was sol: {Subscript[x, 1][z,t]->InterpolatingFunction[{{0.,20.},{0.,10.}},<>][t,z],Subscript[x, 2][z,t]->InterpolatingFunction[{{0.,20.},{0.,10.}},<>][t,z],y[z,t]->InterpolatingFunction[{{0.,20.},{0.,10.}},<>][t,z]} and you entered Subscript[x, 1][0.1, 3] /. sol Subscript[x, 2][0.1, 1] /. sol y[0.5, 1] /. sol The left hand sides of rules in sol are NOT THERE in those statements, so Replace doesn't do anything. In the plots, you used y[z, t] /. sol, Subscript[x, 1][z, t] /. sol, and Subscript[x, 2][z, t] /. sol. You used the left hand sides of rules in "sol", and Replace replaced them as advertised. A more general rule could be used, for instance sol = {Subscript[x, 1][z_, t_] -> one[t, z], Subscript[x, 2][z_, t_] -> two[t, z], y[z_, t_] -> three[t, z]}; Subscript[x, 1][0.1, 3] /. sol Subscript[x, 2][0.1, 1] /. sol y[0.5, 1] /. sol one[3, 0.1] two[1, 0.1] three[1, 0.5] But that's not the kind of solutions given by the solvers, and Replace can't replace what isn't there. Bobby On Wed, 04 Jan 2012 04:03:29 -0600, gac <g.crlsn at gmail.com> wrote: > 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. > -- DrMajorBob at yahoo.com
- References:
- Re: Rule replacement doesn't work after NDSolve?
- From: gac <g.crlsn@gmail.com>
- Re: Rule replacement doesn't work after NDSolve?