MathGroup Archive 2007

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

Search the Archive

Re: Loop, deleting intermediary results, lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78789] Re: Loop, deleting intermediary results, lists
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 10 Jul 2007 06:18:47 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f6qed5$a43$1@smc.vnet.net>

kristoph wrote:
> Dear all,
> 
> Assume we have f[x_]:=f[x]=x^2 within some For[x=1,x<=3,x++...] loop.
> At each iteration we assign a value to f[x] which results in a total
> of three values.
> 
> I would like to delete at each iteration x the previous result of f.
> Thus, we would only have a result of f[3] but not for the f[1] and
> f[2].
> 
> This is a very simplified example but I think it describes my problem
> well enough. The problem I have is that I generate via a loop a
> massive amount of data in form of a list which I combine in one big
> list but I don't need the intermediary results. At the moment
> Mathematica 5.2 is always crashing and I think it has to do with these
> lists.
> 
> I didn't us f[x-1]={} within the loop so far but I thought there might
> be a more elegant way to handle the problem.
> 
> Thanks in advance,
> Kristoph

You can get rid of the symbol f[n] by adding the assignment f[n]=. at 
the end of the for loop.

In[1]:= f[x_] := f[x] = x^2
f /@ Range[3]
Information["f", LongForm -> False]
f[1] =.
f[2] =.
Information["f", LongForm -> False]

Out[2]= {1, 4, 9}

Global`f

f[1]=1

f[2]=4

f[3]=9

f[x_]:=f[x]=x^2

Global`f

f[3]=9

f[x_]:=f[x]=x^2

So in your case you would have something like

f[0] = something;
For[x=1,x<=3,x++, f[x]=f[x-1];f[x-1]=.]

Regards,
Jean-Marc


  • Prev by Date: How to factor a rational
  • Next by Date: Re: Axes and Frame
  • Previous by thread: Re: Loop, deleting intermediary results, lists
  • Next by thread: a bug in Integrate