Re: Differences between recursions and limit

• To: mathgroup at smc.vnet.net
• Subject: [mg60553] Re: Differences between recursions and limit
• From: albert <awnl at arcor.de>
• Date: Tue, 20 Sep 2005 05:19:11 -0400 (EDT)
• References: <dgm01k\$njm\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

> I want to know
> why these two recursions,doing the same thing,
> are the first one much more slow than the second

because you are recalculating all intermediate results over and over again
in the first case. Try instead:

x[0] = 0;
x[k_] := x[k] = .25*(1 + x[k - 1] + (x[k - 1])^2 + (x[k - 1])^3);

For[k = 1, k < 12, Print[k, " ", SetPrecision[x[k], 30]]; k++] // Timing

how this combination of SetDelayed (:=) and Set (=) works is explained in
the online documentation (section 2.5.9 Functions That Remember Values They
Have Found)...

for your other question -- I don't remember the correct conditions for the
following to work, but in your case the result (0.4142...) you are after
can be received with (I get a negative result and 1 as other solutions of
the NSolve, but these can be excluded with your starting value):

NSolve[x == .25*(1 + x + (x)^2 + (x)^3), x]

Albert

```

• Prev by Date: Re: writing a function with unknown number of paramters
• Next by Date: Re: Re: Outputting MatrixForm to Word
• Previous by thread: Re: Differences between recursions and limit
• Next by thread: Re: Re: Differences between recursions and limit