Re: Computed dynamic functions
- To: mathgroup@smc.vnet.net
- Subject: [mg11490] Re: Computed dynamic functions
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Fri, 13 Mar 1998 12:21:35 -0500
- References: <6e8153$n79@smc.vnet.net>
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