MathGroup Archive 1998

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

Search the Archive

Re: Computed dynamic functions



Gabriel Alvarez Galindo wrote:
> 
> Hi - How can I achieve f[x_]:= f[x] = theResultOfAnEvaluation ?

Gabriel:
You nearly have it:
Two examples

1)

f[x_?NumericQ]:= f[x] = NIntegrate[t^t,{t,1,x}]

f[3]

13.7251

?f

"Global`f"

f[3] = 13.72510514057755
 
f[(x_)?NumericQ] := f[x] = NIntegrate[t^t, {t, 1, x}]


2)

fib[0] = fib[1] = 1;

fib[n_Integer?(#>1&)] := fib[n] = fib[n-1]+fib[n-2]

fib[2]

2

?fib

"Global`fib"

fib[0] = 1
 
fib[1] = 1
 
fib[2] = 2
 
fib[(n_Integer)?(#1 > 1 & )] := fib[n] = fib[n - 1] + fib[n - 2]

-- 
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642




  • Prev by Date: Re: Re: Change viewpoints in real time
  • Next by Date: Re: Plotting points in 3D
  • Prev by thread: Computed dynamic functions
  • Next by thread: Question about Coefficient