Re: Re: Recovering f[z] values?
- To: mathgroup at smc.vnet.net
- Subject: [mg42722] Re: [mg42700] Re: Recovering f[z] values?
- From: Dr Bob <drbob at bigfoot.com>
- Date: Wed, 23 Jul 2003 00:25:13 -0400 (EDT)
- References: <bfgb8a$8g4$1@smc.vnet.net> <200307220840.EAA19506@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
ClearAll[memory,f] memory = {}; f[z_] := Block[{result}, result = Sin[z/10]; AppendTo[memory, {z, result}]; result] Do[f[Random[Integer, {0, 20}]], {5}]; or ClearAll[memory, f] f[z_] := Sin[z/10] memory[f_] := {} memory[f_, x_] := Last@Last@(memory[f] = Join[memory[f], {{x, f[x]}}]) Table[memory[f, Random[Integer, {0, 20}]], {5}] Table[memory[Exp, Random[Integer, {0, 20}]], {5}] memory[f] memory[Exp] Bob's method is simpler and more efficient, but it loses information about how many times, and in what order, each argument was used. If that's not important, then go with it. Bobby On Tue, 22 Jul 2003 04:40:37 -0400 (EDT), Bob Hanlon <bobhanlon at aol.com> wrote: > Clear[f, z]; > > Include memory in the definition of f > > f[z_] := f[z] = Sin[z/10]; > > Use f > > Do[f[Random[Integer,{0,20}]], {5}]; > > Recall use of f > > {#[[1,1,1]],#[[2]]}& /@ Drop[DownValues[f],-1] > > {{0, 0}, {6, Sin[3/5]}, {18, Sin[9/5]}, {20, Sin[2]}} > > Reset f without losing definition > > DownValues[f]=Last[DownValues[f]]; > > Reuse f > > Do[f[Random[Integer,{0,20}]], {5}]; > > Recall use of f since reset > > {#[[1,1,1]],#[[2]]}& /@ Drop[DownValues[f],-1] > > {{2, Sin[1/5]}, {3, Sin[3/10]}, {7, Sin[7/10]}, {13, Sin[13/10]}} > > > Bob Hanlon > > In article <bfgb8a$8g4$1 at smc.vnet.net>, AES/newspost > <siegman at stanford.edu> > wrote: > > << During the course of a long notebook evaluation a certain function > > f[z] = some function of z > > gets executed multiple times for various values of z which are no longer > remembered. Near the end of the calculation it's desired to recover all > these values, perhaps in a list > > {{z1,f[z1]}, {z2,f[z2}, . . . } > > Is there a simple way to do this? > -- majort at cox-internet.com Bobby R. Treat
- References:
- Re: Recovering f[z] values?
- From: bobhanlon@aol.com (Bob Hanlon)
- Re: Recovering f[z] values?