Help correcting the sequence function

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

답변 (1개)

DGM
DGM 2021년 7월 19일
편집: DGM 2021년 7월 19일

0 개 추천

% 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
fibb = 1×10
1 3 10 33 109 360 1189 3927 12970 42837

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2021년 7월 19일

편집:

DGM
2021년 7월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by