0
$\begingroup$

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?

$\endgroup$
0

2 Answers 2

0
$\begingroup$

Nest is probably what you need.

Nest[f, x, 40]

enter image description here

Also worth reading the docs for Fold and FixedPoint

$\endgroup$
1
  • $\begingroup$ Thank you, especially for pointing out the documentation. FixedPoint is also an interesting function. $\endgroup$
    – Nick
    Jan 30, 2015 at 4:14
2
$\begingroup$
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

$\endgroup$
1
  • $\begingroup$ 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! $\endgroup$
    – Nick
    Jan 30, 2015 at 6:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.