How do I get formula for the nth term of this on matlab?

sqrt(1+2sqrt(1+3sqrt(1+4sqrt(1+...))))
I know this limit is 3...but I need to get matlab to give me the first 40 terms. I am confused on how to code it.

댓글 수: 3

Doesn't it need some kind of initialisation condition?
I am not sure what that entrails. I keep trying to figure out a formula but nothing works.
I think the sucession should be like this:
a_1=sqrt(1)
a_2=sqrt(1 + 2*sqrt(1))
a_3=sqrt(1 + 2*sqrt(1 + 3*sqrt(1)))
...
Has the same limit and doesn't need initial value for recursion.

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2014년 9월 24일
What would be inside the parentheses of the 40th sqrt()? Just a 1?
Try a for loop and see what happens
s(40) = 1;
for k = 39 : -1 : 1
s(k) = k * sqrt(s(k+1)+1)
end

댓글 수: 8

Hello, I don't understand why s(40)=1...s(40) is too large for me to put in my calculator.
I believe s(1)=1 the sequence starts with 1, so I am a bit confused
Calculator?! We're using MATLAB programs here. Did you actually even try the code?
Yes, I tried it. it gave me a lot of numbers. I'm sorry I am a noob to all this. :s
How come you got s(40)=1?
Okay, upon examination, I see you started a(1)=1 and you are going backwards?
There is no "a". If you want, put a semicolon at the end of the s(k) line and just put s on its own line after the loop to have it print out the whole array.
I keep, but it won't give me whole array appears to only give value of s(n) only. After I have array, how can I plot it to see graph?

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Stephen23
Stephen23 2014년 9월 24일
편집: Stephen23 2014년 9월 24일

1 개 추천

You could try writing a for loop. The loop would just need to increment down itr = 40:-1:1, and calculates itr*sqrt(1+last_val) , with last_value defined before the loop (what value?).
Check it first with a small number of iterations first (1, 2, 3), to confirm that it calculates the expected values. Then try it with more iterations.
Roger Stafford
Roger Stafford 2014년 9월 24일
편집: Roger Stafford 2014년 9월 24일

1 개 추천

It doesn't matter what you initialize it at, the limit as n approaches infinity is always 2, not 3.
Correction: You were right. I was in error. The limit is always 3 no matter what your initial value is.
Roger Stafford
Roger Stafford 2014년 9월 25일
편집: Roger Stafford 2014년 9월 25일
Since I made an error in my first answer, here is a bit more information. The problem can be expressed this way:
x(1) = sqrt(1+2*x(2))
x(2) = sqrt(1+3*x(3))
x(3) = sqrt(1+4*x(4))
...
x(n-1) = sqrt(1+n*x(n))
Now suppose x(n) were equal to n+2. Then
x(n-1) = sqrt(1+n*(n+2)) = sqrt((n+1)^2) = n+1
x(n-2) = sqrt(1+(n-1)*(n+1)) = sqrt(n^2) = n
...
x(1) = 3
However, if x(n) is not equal to n+2, express its ratio to n+2 as x(n)/(n+2) = 1+e(n). Then we have
1+e(n-1) = x(n-1)/(n+1)
= sqrt((1+n*(n+2)*(1+e(n)))/(n+1)^2)
= sqrt(1+n*(n+2)/(n+1)^2*e(n))
e(n-1) = sqrt(1+n*(n+2)/(n+1)^2*e(n)) - 1
This will always approach zero for sufficiently large n to start with and hence the limit for x(1) must be 3 no matter what the initial value is.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2014년 9월 24일

댓글:

2014년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by