Iterative code sequence error
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Torsten
on 18 Aug 2022
f1 = 1;
f2 = 1;
f3 = 1;
n = 10;
f = sequence(n,f1,f2,f3)
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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!