Help correcting the sequence function
Afficher commentaires plus anciens
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

Réponses (1)
% 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
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!