How to code binary Fibonacci sequence?

I was asked to code the binary fibonacci sequence which outputs the following: f_0={0}, f_1={1} where the successive elements of the sequence are obtained as the concatenation of the two previous ones: f_k = {f_{k-1} f_{k-2}} with k>1
f_2={1 0}
f_3={1 0 1}
f_4={1 0 1 1 0}
f_5={1 0 1 1 0 1 0 1}
f_6={1 0 1 1 0 1 0 1 1 0 1 1 0}, ...
To concatenate, I think I have to use the horzcat function. Can anyone help me with this?

 採用された回答

Catalytic
Catalytic 2022 年 7 月 19 日

0 投票

"where the successive elements of the sequence are obtained as the concatenation of the two previous ones"
No, see -

3 件のコメント

Lope
Lope 2022 年 7 月 19 日
Catalytic
Catalytic 2022 年 7 月 19 日
n=4;
a=0;b=1;
for i=1:n
c=[b,a]
[a,b]=deal(b,c);
end
c = 1×2
1 0
c = 1×3
1 0 1
c = 1×5
1 0 1 1 0
c = 1×8
1 0 1 1 0 1 0 1
Lope
Lope 2022 年 7 月 20 日
Thank you so much @Catalytic

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2021a

タグ

質問済み:

2022 年 7 月 19 日

コメント済み:

2022 年 7 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by