# How to continuous apply a function to an argument? [duplicate]

In order to calculate x = sqrt(1 + x) for a given number x, 40 times, I tried this:

f [x_] := Sqrt[1 + x]
N[Map[f, x = Range[40]]]


However, I got to apply the function f to every number from 1 to 40, not continuously.

The process should be Sqrt[Sqrt[Sqrt...[1+x]]]

In Matlab, I could do

x = 3
for k = 1:41
x = sqrt(1 + x)
end


Data in Mathematica is inmutable by default, how can I do this?

Nest is probably what you need.

Nest[f, x, 40]


Also worth reading the docs for Fold and FixedPoint

• Thank you, especially for pointing out the documentation. FixedPoint is also an interesting function.
– Nick
Jan 30, 2015 at 4:14
f[x_] = Sqrt[1 + x];


The fixed point is the golden ratio, independent of the starting value

(x /. Solve[x == f[x], x][[1]]) == GoldenRatio


True

GoldenRatio == f[GoldenRatio] // FullSimplify


True

FixedPoint[f, {.01, .1, 1., 1.1, 10.}] // Union


{1.61803}

%[[1]] // RootApproximant


1/2 (1 + Sqrt[5])

% == GoldenRatio


True

• Yes, I'm leaning Mathematica by calculating the Golden Ratio. It's good to know that there's even a GoldenRatio built-in the Mathematica. Thank you!
– Nick
Jan 30, 2015 at 6:05