Help correcting the sequence function
1 view (last 30 days)
Show older comments
Hello , i was wondering if anyone could help me out a little bit , so am writing a function ,which calculates sequence in a matrix diaognaly , but am little bit stuck ,its not givng the numbers that i want
n=input('sequence_matrix_')
fibb=[1,3:n];
for i=3:n
fibb(i)=fibb(i-1)*3+1;
end
(fibb)
I want it to display
1,3,10,33,109,360
0 Comments
Answers (1)
DGM
on 19 Jul 2021
Edited: DGM
on 19 Jul 2021
% if you're asking the user for a number, use a clear description
% "sequence matrix" doesn't tell anyone what the number means
n = 10; % number of elements in sequence
fibb = zeros(1,n);
fibb(1:2) = [1 3]; % only the first two numbers are used
for i = 3:n
fibb(i) = fibb(i-1)*3 + fibb(i-2); % only +1 for first iteration
end
fibb
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!