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


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

Re: Rule replacement doesn't work after NDSolve?

Started byBob Hanlon <hanlonr357@gmail.com>
First post2012-01-03 10:31 +0000
Last post2012-01-03 10:31 +0000
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Rule replacement doesn't work after NDSolve? Bob Hanlon <hanlonr357@gmail.com> - 2012-01-03 10:31 +0000

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

FromBob Hanlon <hanlonr357@gmail.com>
Date2012-01-03 10:31 +0000
SubjectRe: Rule replacement doesn't work after NDSolve?
Message-ID<jdulef$jqe$1@smc.vnet.net>
n = 2;
tf = 20;
varsx = Table[Subscript[x, i][z, t], {i, n}];
varsy = Table[y[z, t], {i, 1, 1}];

eqnsx = Table[{\!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\(
\(\*SubscriptBox[\(x\), \(i\)]\)[z, t]\)\) ==  y[z, t] \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(j = 1\), \(n\)]\(\((i - j)\)
\(\*SubscriptBox[\(x\), \(j\)]\)[z, t]\)\),
   Subscript[x, i][z, 0] == Sin[2 i Pi z]}, {i, n}];

eqnsy = Table[{\!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\(y[z, t]\)\) == - y[z, t] +
     Exp[-(t - tf/4)^2], y[z, 0] == 0}, {j, 1, 1}];

vars = Join[varsx, varsy];
eqns = Join[eqnsx, eqnsy];

sol = NDSolve[eqns, vars, {t, 0, tf}, {z, 0, 10}, MaxStepSize -> 0.01,
MaxSteps -> 10^5, Method -> "ExplicitRungeKutta"][[1]]

{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]}

Note that the LHS of the rules in sol do not involve patterns. The
rules must be applied before the arguments are set (as is done in the
plots).

Subscript[x, 1][z,t] /. sol/.{z->0.1,t->3}

0.587097

Subscript[x, 2][z,t] /. sol/.{z->0.1,t->1}

0.951057

y[z,t]/.sol/.{z->0.5,t->1}

1.22233*10^-8

Alternatively, use pure functions for the interpolation

vars2=Head/@vars;

sol2 = NDSolve[eqns, vars2, {t, 0, tf}, {z, 0, 10}, MaxStepSize ->
0.01, MaxSteps -> 10^5, Method -> "ExplicitRungeKutta"][[1]]

{Subscript[x, 1]->InterpolatingFunction[{{0.,10.},{0.,20.}},<>],
Subscript[x, 2]->InterpolatingFunction[{{0.,10.},{0.,20.}},<>],
y->InterpolatingFunction[{{0.,10.},{0.,20.}},<>]}

Subscript[x, 1][0.1,3]/.sol2

0.587097

Subscript[x, 2][0.1,1]/.sol2

0.951057

y[0.5,1]/.sol2

1.22233*10^-8


Bob Hanlon

On Mon, Jan 2, 2012 at 2:48 AM, gac <g.crlsn@gmail.com> wrote:
> Can anyone explain why the three rule replacement steps after NDSolve don=
't work, but the three Plot3D commands do?  Thanks.
>
> n = 2;
> tf = 20;
> varsx = Table[Subscript[x, i][z, t], {i, n}];
> varsy = Table[y[z, t], {i, 1, 1}];
>
> eqnsx = Table[{\!\(
> \*SubscriptBox[\(\[PartialD]\), \(t\)]\(
> \(\*SubscriptBox[\(x\), \(i\)]\)[z, t]\)\) ==  y[z, t] \!\(
> \*UnderoverscriptBox[\(\[Sum]\), \(j = 1\), \(n\)]\(\((i - j)\)\
> \(\*SubscriptBox[\(x\), \(j\)]\)[z, t]\)\),
>    Subscript[x, i][z, 0] == Sin[2 i Pi z]}, {i, n}];
>
> eqnsy = Table[{\!\(
> \*SubscriptBox[\(\[PartialD]\), \(t\)]\(y[z, t]\)\) == - y[z, t] +
>      Exp[-(t - tf/4)^2], y[z, 0] == 0}, {j, 1, 1}];
>
> vars = Join[varsx, varsy];
> eqns = Join[eqnsx, eqnsy];
>
> sol = NDSolve[eqns, vars, {t, 0, tf}, {z, 0, 10}, DependentVariables ->=
 vars, MaxStepSize -> 0.01, MaxSteps -> 10^5, Method -> "ExplicitRungeKutta=
"][[1]]
>
> Subscript[x, 1][0.1, 3] /. sol
> Subscript[x, 2][0.1, 1] /. sol
> y[0.5, 1] /. sol
>
> Grid[{{Plot3D[y[z, t] /. sol, {t, 0, tf}, {z, 0, 1}, PlotLabel -> "y[z,t]=
", AxesLabel -> {"t", "z"}, PlotRange -> All, ImageSize -> 400],
> Plot3D[Subscript[x, 1][z, t] /. sol, {t, 0, tf}, {z, 0, 1}, PlotLabel -> =
"\!\(\*SubscriptBox[\(x\), \(1\)]\)[z,t]]", AxesLabel -> {"t", "z"}, PlotRa=
nge -> All, ImageSize -> 400]},
> {Plot3D[Subscript[x, 2][z, t] /. sol, {t, 0, tf}, {z, 0, 1}, PlotLabel ->=
 "\!\(\*SubscriptBox[\(x\), \(2\)]\)[z,t]", AxesLabel -> {"t", "z"}, PlotRa=
nge -> All, ImageSize -> 400],}}]
>

[toc] | [standalone]


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


csiph-web