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

 采纳的回答

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 Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by