MathGroup Archive 2010

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

Search the Archive

Re: Modification of Variable in NDSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108007] Re: Modification of Variable in NDSolve
  • From: Shawn Garbett <shawn.garbett at gmail.com>
  • Date: Fri, 5 Mar 2010 04:31:55 -0500 (EST)
  • References: <hmiikh$3r6$1@smc.vnet.net> <hmlese$jmc$1@smc.vnet.net>

I took these suggestion into account and now have the following, it's
crude but works. If I can refine it into a loop, then I'll be done.

First Interval

x1 = Reap[NDSolve[
   {A'[t] == dA, B'[t] == dB, F'[t] == dF,
    A[0] == 1, B[0] == 1, F[0] == 1},
   {A, B, F}, {t, 0, 100},
   Method -> {
     "EventLocator",
     "Event" -> F[t] - 5,
     "Direction" -> 1,
     "EventAction" :> Sow[t]
     }
   ]]

sol1 = x1[[1]][[1]]

div1 = x1[[2]][[1]][[1]]

Second Interval

x2 = Reap[NDSolve[
   {A'[t] == dA, B'[t] == dB, F'[t] == dF,
    A[div1] == (A[div1] /. sol1),
    B[div1] == (B[div1] /. sol1),
    F[div1] == (F[div1] /. sol1)/2},
   {A, B, F}, {t, div1, 100},
   Method -> {
     "EventLocator",
     "Event" -> F[t] - 5,
     "Direction" -> 1,
     "EventAction" :> Sow[t]
     }
   ]]

sol2 = x2[[1]][[1]]

div2 = x2[[2]][[1]][[1]]

Third Interval

x3 = Reap[NDSolve[
   {A'[t] == dA, B'[t] == dB, F'[t] == dF,
    A[div2] == (A[div2] /. sol2),
    B[div2] == (B[div2] /. sol2),
    F[div2] == (F[div2] /. sol2)/2},
   {A, B, F}, {t, div2, 100},
   Method -> {
     "EventLocator",
     "Event" -> F[t] - 5,
     "Direction" -> 1,
     "EventAction" :> Sow[t]
     }
   ]]

sol3 = x3[[1]][[1]]

div3 = x3[[2]][[1]][[1]]

AA[t_ /; t <= div1] := (A[t] /. sol1);
AA[t_ /; div1 < t <= div2] := (A[t] /. sol2) ;
AA[t_ /; div2 < t <= div3] := (A[t] /. sol3);

BB[t_ /; t <= div1] := (B[t] /. sol1);
BB[t_ /; div1 < t <= div2] := (B[t] /. sol2) ;
BB[t_ /; div2 < t <= div3] := (B[t] /. sol3);

FF[t_ /; t <= div1] := (F[t] /. sol1);
FF[t_ /; div1 < t <= div2] := (F[t] /. sol2) ;
FF[t_ /; div2 < t <= div3] := (F[t] /. sol3);

disp = Plot[#[t], {t, 0, div3}, PlotRange -> All] &;
GraphicsGrid[Map[disp, {{AA, BB}, {FF}}, {2}]]



  • Prev by Date: Re: Mathematica and LaTeX
  • Next by Date: Re: Re: learning calculus through mathematica
  • Previous by thread: Re: Modification of Variable in NDSolve
  • Next by thread: Re: Re: Modification of Variable in NDSolve