MathGroup Archive 2009

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

Search the Archive

NDSolve: Affecting dependent variable during solution?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105592] NDSolve: Affecting dependent variable during solution?
  • From: David Szekely <D.Szekely at victorchang.edu.au>
  • Date: Thu, 10 Dec 2009 04:57:35 -0500 (EST)
  • References: <heqf01$1m4$1@smc.vnet.net> <200912091043.FAA16763@smc.vnet.net>

Hi,
I'm trying to solve a system of ODEs in Mathematica where the immediate value of one of the dependent variables changes during the course of the evaluation.
For example, the system A -> B at a rate of 1 s^-1, and B -> A at a rate of 1 s^-1, A[0] = 1, B[0] = 0, is easily set up:

k1 = 1; km1 = 1;
sol = NDSolve[{A'[t] == km1 B[t] - k1 A[t], B'[t] == k1 A[t] - km1 B[t], A[0] == 1, B[0] == 0}, {A, B}, {t, 0, 10}];

But suppose I want to inject 1 unit of A into the system at t = 4. I would need a term in the NDSolve which looked something like

A[t] == A[t] + If[t == 4, 1, 0];

Or alternatively

Method -> {"EventLocator", "Event" -> t == 4, "EventAction" :> A[t] -> A[t] + 1

But neither of these work (because they're extremely poorly designed :( ). Does anyone know a solution to this?
Note that running 2 separate NDSolve operations, namely one for t = 0 to 4, and another for t = 4 to 10 is not an option for me.

The final output should look exactly like this:

ListLinePlot[{{{0., 1.}, {0.2, 0.8351}, {0.4, 0.7246}, {0.6, 0.650597}, {0. 8, 0.600948}, {1, 0.567668}, {1.2, 0.545359}, {1.4, 0.530405}, {1.6,
   0.520381}, {1.8, 0.513662}, {2, 0.509158}, {2.2, 0.506139}, {2.4, 0.504115}, {2.6, 0.502758}, {2.8, 0.501849}, {3, 0.501239}, {3.2, 0.500831}, {3.4, 0.500557}, {3.6, 0.500373}, {3.8, 0.50025}, {4, 0.500168}, {4.2, 1.33516}, {4.4, 1.22466}, {4.6, 1.1506}, {4.8, 1.10095}, {5, 1.06767}, {5.2, 1.04536}, {5.4, 1.0304}, {5.6, 1.02038}, {5.8, 1.01366}, {6, 1.00916}, {6.2, 1.00614}, {6.4,
   1.00411}, {6.6, 1.00276}, {6.8, 1.00185}, {7, 1.00124}, {7.2, 1.00083}, {7.4, 1.00056}, {7.6, 1.00037}, {7.8, 1.00025}, {8,
   1.00017}},
{{0, -5.43292*10^-21}, {0.2, 0.16484}, {0.4, 0.275336}, {0.6, 0.349403}, {0.8, 0.399052}, {1, 0.432332}, {1.2,
   0.454641}, {1.4, 0.469595}, {1.6, 0.479619}, {1.8, 0.486338}, {2, 0.490842}, {2.2, 0.493861}, {2.4, 0.495885}, {2.6, 0.497242}, {2.8, 0.498151}, {3, 0.498761}, {3.2, 0.499169}, {3.4, 0.499443}, {3.6, 0.499627}, {3.8, 0.49975}, {4., 0.499832}, {4.2, 0.66484}, {4.4, 0.775336}, {4.6, 0.849403}, {4.8, 0.899052}, {5, 0.932332}, {5.2, 0.954641}, {5.4, 0.969595}, {5.6, 0.979619}, {5.8, 0.986338}, {6, 0.990842}, {6.2, 0.993861}, {6.4, 0.995885}, {6.6,0.997242}, {6.8, 0.998151}, {7, 0.998761}, {7.2, 0.999169}, {7.4, 0.999443 }, {7.6, 0.999627}, {7.8, 0.99975}, {8, 0.999832}}}]


  • Prev by Date: Re: Possible bug in Opacity[] with plotting function that uses UnitStep?
  • Next by Date: Re: would like to compute a tensor derivative of a function and evaluate
  • Previous by thread: Re: Bug ??????
  • Next by thread: Re: Combine images, Show[] and its effect on AspectRatio. Plot, Epilog,