Re: Using "If" and "NDSolve" together

*To*: mathgroup at smc.vnet.net*Subject*: [mg106842] Re: [mg106781] Using "If" and "NDSolve" together*From*: DrMajorBob <btreat1 at austin.rr.com>*Date*: Sun, 24 Jan 2010 05:45:45 -0500 (EST)*References*: <201001231233.HAA16276@smc.vnet.net>*Reply-to*: drmajorbob at yahoo.com

Oh, what a tangled web you weave. Clear[funcao] funcao[first_, last_] := Module[{k0 = 10^-2, k1 = 10^-5, k2 = 10^-6, k3 = 10, a, b, c}, a = a /. First@ NDSolve[{a'[t] == k0 Boole[first <= t <= last] - k1 a[t], b'[t] == k1 a[t] - k2 b[t], c'[t] == k2 b[t] - k3 c[t], a[0] == 2 10^-6, b[0] == 0, c[0] == 0}, {a, b, c}, {t, 0, 1000}]; Plot[a@t, {t, 0, 1000}, PlotRange -> All] ] funcao[0, 100] funcao[0, 900] funcao[100, 900] Bobby On Sat, 23 Jan 2010 06:33:50 -0600, Benfeitas <rui.benfeitas at gmail.com> wrote: > Hello! > > I have a tricky job to do: I want to simulate something, and want to > assign a value to a variable under certain conditions. Those are, if > time is within a certain interval, I want that variable to have that > value. Otherwise, I want it to have other value. > > Until now, I have been trying to use the following command: > > Funcao[first_, last_] := > Plot[A[t] /. > NDSolve[ > {A'[t] == k0 A0 - k1 A[t], B'[t] == k1 A[t] - k2 B[t], > C'[t] == k2 B[t] - k3 C[t], A[0] == 2 10^-6, B[0] == 0, > C[0] == 0} /. k0 -> 10^-2 /. k1 -> 10^-5 /. k2 -> 10^-6 /. > k3 -> 10^1 /. If[first < t < last, A0 -> 1, 0], {A, B, C}, > {t, > 0, 1000}], {t, 0, 1000}] > > > > for some reason, it is not working, and I cannot figure out why... > > With that command I will want to plot A[t], for t->{0,1000}, and > considering that A0->1 if first<t<last, and A0->0 if t<first or > t>last. That way, A[t] should be higher if first<t<last. > > Can you guys please give me some tips? Thanks > -- DrMajorBob at yahoo.com

**References**:**Using "If" and "NDSolve" together***From:*Benfeitas <rui.benfeitas@gmail.com>