MathGroup Archive 2004

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

Search the Archive

Re: stepwise ode. why does this fail?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48421] Re: stepwise ode. why does this fail?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sat, 29 May 2004 03:06:42 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <c96i6n$ikr$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

because a0 is a function of t and you don't like to
tell Mathematica this, but:

Clear[a0]
k1 = 1/10;
k2 = 1/20;
a0[t_] := Which[
    t < 0, 0,
0 <= t <= 200, 1/20,
200 <= t <= 600, 0,
600 <= t, 1/20]

ndsolution = 
  NDSolve[{b'[t] == -k2 b[t] y[t], x'[t] == -k1 a0[t] x[t] + k2 b[t]
y[t], 
      y'[t] == k1 *a0[t]x[t] - k2 b[t] y[t], b[0] == 1, x[0] == 1, 
      y[0] == 0}, {b, x, y}, {t, 0, 1000}]

work as expected.

Regards
  Jens

sean kim wrote:
> 
> Why does this fail? I don't understand. I think it's because the
> function defining the a0 is delayed...  is that right?
> 
> if so, how do i define a stepwise ode in Mathematica? I wanted to make a0= 0
> at time 0, then 1/20 for given time then 0 and again opver next time
> frame then 1/20 again for the rest of the time.
> 
> below is my attempt. but it brings back
> 
> NDSolve::ndnum: Encountered non-numerical value for a derivative at t
> == 0.
> 
> k1 = 1/10;
> k2 = 1/20;
> a0 := 0 /; t < 0 ;
> a0 := 1/20 /; 0 <= t <= 200 ;
> a0 := 0 /; 200 <= t <= 600 ;
> a0 := 1/20 /; 600 <= t <= 1000;
> 
> ndsolution =
> NDSolve[{b'[t] == -k2 b[t] y[t], x'[t] == -k1 a0 x[t] + k2 b[t] y[t],
> y'[t] == k1 a0 x[t] - k2 b[t] y[t], b[0] == 1, x[0] == 1, y[0] == 0},
> {b, x, y}, {t, 0, 1000}]
> 
> thanks all very much in advance for any and all comments.
> 
> sean


  • Prev by Date: checking accuracy with stepwise ode.
  • Next by Date: Re: matrix operations
  • Previous by thread: stepwise ode. why does this fail?
  • Next by thread: Mathematica courses in Amsterdam