Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

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

Search the Archive

Re: procedures

  • To: mathgroup at
  • Subject: [mg96950] Re: [mg96937] procedures
  • From: Sseziwa Mukasa <mukasa at>
  • Date: Sat, 28 Feb 2009 06:40:15 -0500 (EST)
  • References: <> <> <>

On Feb 27, 2009, at 10:45 AM, Davide Venturelli wrote:

> Thank you for the answer!
>> What is the purpose of assigning its value to
>> itself?
> I am evaluating a recursive function.
> I want to store every computed value in such a way that next time the
> code calls it, it remembers if it has already evaluated it.
> So while I need := for definition of the recursive functions, I use  
> the
> Do loop to assign actual values to the array.
> Do you have a better idea?

You can implement functions with memory as

F[x_]:=f[x]=(*body goes here*)

This would obviate the need for Do loop, just evaluating D[x,n] would  
be sufficient.

Search for FunctionsThatRememberValuesTheyHaveFound in the  
Mathematica help documentation (for v7).

> I now have another problem, anyway!
> When I do FindRoot[f[x],{x,0}] it looks for all instances of x in the
> definition of the function, and THEN evaluate the function for the
> symbol X.

I think this occurs because FindRoot defaults to Newton's method and  
it needs to take the derivative of the expression.

> What I want is to override this symbolic method and call f[x] with the
> numerical value of x, since in the definition of f[x] I have recursive
> functions that would imply to evaluate a huge polynomial of x, and
> keeping track of all the terms is really lengthy.
> While if I substitute x=x0 at each recursive step, the computation is
> less costy.
> So is there a way to tell mathematica in FindRoot to call the function
> with numerical values, like it was a black box?

This comes up from time to time on this mailing list.  The usual  
suggestion is to make the function definition valid only for numeric  
arguments see 

for example.

Hope that helped,

Sseziwa Mukasa

  • Prev by Date: Re: newbie: programmatic sequence of plots?
  • Next by Date: Re: Show problem: combining ListPlot and Plot
  • Previous by thread: Re: procedures
  • Next by thread: Re: procedures