Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1994
*January
*February
*March
*April
*May
*June
*July
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1994

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

Search the Archive

Question about function definitions

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg245] Question about function definitions
  • From: Scott Herod <sherod at boussinesq.Colorado.EDU>
  • Date: Mon, 28 Nov 1994 13:10:01 -0700 (MST)

Here is a question related to the issue of multiple function
definitions.  First let me present some code segments with examples of
their execution.

-----------File delsol.m:

delay[num_, T_, z_] := Module[{},
  f[s_] := 0.7 + 0.1 s;
  witchargs = {};
  For[k = 0, k <= num, k++,
    sol = NDSolve[{y'[t] + y[t] == f[t] ( 2 - f[t]^z),
        y[T*k] == f[T*(k+1)]}, y, {t,T*k,T*(k+1)}];
(*  Clear[f]; *)
    f[s_] := Evaluate[(y /. Flatten[sol])][s-T];
    witchargs = {witchargs, t <= T*(k+1), Evaluate[(y /. Flatten[sol])][t]}
  ];
g[t_] = Apply[Which, Flatten[witchargs]];
];


---------Example Run

Mathematica 2.2 for Solaris
Copyright 1988-93 Wolfram Research, Inc.
License valid through 28 Nov 1995.
 -- Open Look graphics initialized -- 

In[1]:= <<delsol.m

In[2]:= delay[3,2,3]

In[3]:= ??f
Global`f

f[s_] := 0.7 + 0.1*s
 
f[s$_] := Evaluate[y /. Flatten[sol]][s$ - 2]

----------Discussion

I am computing solutions to a differential-delay equation discussed by
R.M. May in a 1981 paper.  The idea is to iterate on the set of smooth
functions defined on [0,T].  Anyway, this code doesn't work because
the NDSolve routine always sees the first definition of f with the "s"
not the definition with the "s$".  Of course a fix is to clear f each
time through the loop, but I would be interested in understanding why
the $ is appended.  Especially considering the next example.

------------File vartest.m

tes[num_] := Module[{},
  f[t_] := Sin[t];
  For[k = 1, k <= num, k++,
    y = f';
    f[t_] = y[t - 2];
  ]
]

------------Example run

Mathematica 2.2 for Solaris
Copyright 1988-93 Wolfram Research, Inc.
License valid through 28 Nov 1995.
 -- Open Look graphics initialized -- 

In[1]:= <<vartest.m

In[2]:= tes[3]

In[3]:= ??f
Global`f

f[t_] = -Cos[6 - t]

------------Discussion

What is it about the above routine which is different from the first
so that the "$" is not added to the variable $t$?

Scott A. Herod
Program in Applied Mathematics
University of Colorado, Boulder
(sherod at newton.colorado.edu)





  • Prev by Date: RE: Re: Simple command to strip Notebook
  • Next by Date: Problems with MeshRange in ListContourPlot3D: THE FIX
  • Previous by thread: Power Mac Performance
  • Next by thread: Problems with MeshRange in ListContourPlot3D: THE FIX