Which is the smallest natural number n to which it applies a(n)>10?

1 回表示 (過去 30 日間)
Nikodin Sedlarevic
Nikodin Sedlarevic 2021 年 11 月 18 日
編集済み: John D'Errico 2021 年 11 月 18 日
I have recursive sequence a(i)= a(i-1) + a(i-2)^(-1), where is a(1) and a(2) equals 1. So I have to find smallest natural number n to which it applies a(n)>10.
This is my code so far:
a = zeros(1,15);
a(1) = 1;
a(2) = 1;
for i = 3:15
a(i)= a(i-1) + a(i-2)^(-1);
end
Any help?
  2 件のコメント
Stephen23
Stephen23 2021 年 11 月 18 日
@Nikodin Sedlarevic: that recursive sequence does not use b anywhere. What is b for?
Nikodin Sedlarevic
Nikodin Sedlarevic 2021 年 11 月 18 日
Sorry, I will remove it

サインインしてコメントする。

採用された回答

David Hill
David Hill 2021 年 11 月 18 日
a(1)=1;a(2)=1;
for k=3:1000 %pick something to overshoot or use while loop
a(k)=a(k-1)+1/a(k-2);
end
n=find(a>10,1);%48!

その他の回答 (1 件)

John D'Errico
John D'Errico 2021 年 11 月 18 日
編集済み: John D'Errico 2021 年 11 月 18 日
The obvious answer is brute force, thus...
a_i = 1;
a_iplus1 = 1;
plot(a_i,a_iplus1,'o')
hold on
iter = 2;
imax = 1e6;
while (a_iplus1 < 10) && (iter < imax)
iter = iter + 1;
[a_i,a_iplus1] = deal(a_iplus1,a_iplus1 + 1/a_i);
plot(a_i,a_iplus1,'o')
end
grid on
xlabel a_i
ylabel a_iplus1
a_iplus1
a_iplus1 = 10.0922
iter
iter = 48
So when iter = 48, a finally grows larger than 10.
Note that I wrote the code so that no arrays are grown. This is important, since the loop might have gone on forever. This is why I put an upper limit on the loop. The trick using deal to advance the terms is well, just a cute trick.
Does a general analytical solution to this nonlinear difference equation exist? Possibly. Such nonlinear difference equations tend to have "interesting" behaviour. As soon as you dive into the domain of the nonlinear, things can go straight to well, you know where. The plot however, suggests a simple asymptotic behavior, one that makes sense when you look at the expression. Questions now come up, like is there a limiting value? Or will a(i) grow forever, unbounded?

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by