Re: Control Function With NDsolve
- To: mathgroup at smc.vnet.net
- Subject: [mg19338] Re: Control Function With NDsolve
- From: Eckhard Hennig <hennig at itwm.uni-kl.de>
- Date: Fri, 20 Aug 1999 23:09:26 -0400
- Organization: ITWM
- References: <7p5dm5$127@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Don Paddleford schrieb in Nachricht <7p5dm5$127 at smc.vnet.net>... >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? > Don, 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, 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 itwm.uni-kl.de 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 http://www.itwm.uni-kl.de/as/employees/hennig.html ITWM - Makers of Analog Insydes for Mathematica http://www.itwm.uni-kl.de/as/products/ai -----------------------------------------------------------