f(i) = f(i-3)*f(i-1) - f(i-2) using f(1) = 1, f(2) = 1 and f(3) = 1.
function f = iterativeSequence(n)
f(1) = 1;
f(2) = 1;
f(3) = 1;
for i = 4:n
f(n) = (f(i-3)*f(i-1))-f(i-2);
end

 採用された回答

Torsten
Torsten 2022 年 8 月 18 日

1 投票

f1 = 1;
f2 = 1;
f3 = 1;
n = 10;
f = sequence(n,f1,f2,f3)
f = 1×10
1 1 1 0 -1 -1 1 0 -1 -1
function f = sequence(n,f1,f2,f3)
if n < 4
disp('Choose bigger value for n');
f = [f1 f2 f3];
return
end
f = zeros(1,n);
f(1) = f1;
f(2) = f2;
f(3) = f3;
for i = 4:n
f(i) = f(i-3)*f(i-1) - f(i-2);
end
end

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2022 年 8 月 18 日

編集済み:

2023 年 1 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by