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

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!

Risposte (1)

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".

Categorie

Scopri di più su Strategy & Logic in Centro assistenza e File Exchange

Richiesto:

il 17 Set 2017

Risposto:

il 17 Set 2017

Community Treasure Hunt

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

Start Hunting!

Translated by