MathGroup Archive 1999

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

Search the Archive

Re: Control Function With NDsolve

Don Paddleford schrieb in Nachricht <7p5dm5$127 at>...
>In solving a control type dif eq with NDSolve I have the following
>question. Suppose the eq is of the following simplified form
> y'[t]==a*f[y[t]]-b*y[t]
> y[0]==0
>How to define f so that it starts at f=1, and changes to f=0 when y
>reaches ymax, and then changes back to f=1 when y reaches ymin, and so
>on in oscilatory fashion?


you can define such a function as follows. Note that it is important to
define the pattern for f such that it applies only to numeric arguments.
Otherwise, f[y[t]] would be evaluated prematurely in In[3].

In[1]:= f[y_Real] :=
          If[(y > ymax && fval == 1) || (y < ymin && fval == 0),
             fval = 1 - fval,

In[2]:= ymax = 0.9; ymin = 0.1; a = 1; b = 1;

In[3]:= eqs = {y'[t] == a*f[y[t]] - b*y[t], y[0] == 0};

In[4]:= fval = 1; NDSolve[eqs, y[t], {t, 0, 10}];

In[5]:= y1[t_] = y[t] /. First[%];

In[6]:= Plot[y1[t], {t, 0, 10}, PlotRange->All]

-- Eckhard

Dipl.-Ing. Eckhard Hennig      mailto:hennig at
Institut fuer Techno- und Wirtschaftsmathematik e.V. (ITWM)
Erwin-Schroedinger-Strasse,  67663 Kaiserslautern,  Germany
  Voice: +49-(0)631-205-3126    Fax: +49-(0)631-205-4139

     ITWM - Makers of Analog Insydes for Mathematica

  • Prev by Date: Comments in 2-D cells yield corrupt packages
  • Next by Date: Help: How can I set the insertion cursor in a certain cell?
  • Previous by thread: Re: Control Function With NDsolve
  • Next by thread: Re: Control Function With NDsolve