How do you write script to calculate the value of x in the following nested square root for different numbers of square roots

3 views (last 30 days)
lets say x = sqrt(2+sqrt(2+sqrt2+sqrt2+........
how would i be able to write a script that could calculate it? I eventually it would converge to a certain number.
All help is appreciate because i dont even know the first place to start Thanks!

Answers (1)

Image Analyst
Image Analyst on 17 Sep 2017
Ah, it's the old, famous trick recursive equation question. There are lots of these. But what you need to realize is that since x is that, then x is also
x = sqrt(2 + x)
Squaring both sides
x^2 = 2 + x
or
x^2 - x - 2 = 0
Solving for the roots:
>> roots([1, -1, -2])
ans =
2
-1
Other versions can be solved with the same concept - just realize the equation is in there as a "subequation" somewhere, so just replace it with x and solve for x. Easy/trivial once you know the "trick".

Categories

Find more on Puzzles in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!