# Mathematica cannot compute this recursive sequence [closed]

Basically I want to compute $x_{n+1} = (1/2)(x_n + 5/x_n)$.

On Mathematica, I wrote

h[1] := 2
h[n_] := h[n + 1] = (1/2)*(h[n] + 5/h[n])
h[2]


When I tried to compute h[2], I get this error message \$RecursionLimit::reclim: "Recursion depth of 256 exceeded.

It works for easier sequences like f[n] = n f[n+1]. What is wrong?

-
That's because your second definition is wrong. Try h[n_] := h[n] = (1/2)*(h[n-1] + 5/h[n-1]). – J. M. Oct 7 '12 at 2:27
It gave me the same message when I did h[3] – jak Oct 7 '12 at 2:40
Did you Clear your previous definitions of h first? – rcollyer Oct 7 '12 at 2:43
h[1] := 2; h[n_] /; n >= 2 := h[n] = (1/2)(h[n - 1] + 5/h[n - 1]) implements the intended recursion. – whuber Oct 7 '12 at 19:42
RSolve[{h[n+1]==(1/2)*(h[n] + 5/h[n], h[1]==2}, h[n], n] gives what might be a plausible result. – Daniel Lichtblau Oct 7 '12 at 19:44

## closed as too localized by rcollyer, rm -rf♦Oct 7 '12 at 2:58

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.