MATLAB Answers

Make Sequence Function go Diagonal

1 view (last 30 days)
Hi ,how would i make this function go diagonal?,any help would be great
n = input ('sequence_matrix_');
fibb=[1,3:n];
for i=3:n
fibb(i)=fibb(i-1)*3+(i)-2;
end
fibb

Accepted Answer

Sameer Pujari
Sameer Pujari on 19 Jul 2021
Just do this small change
n = input ('sequence_matrix_');
fibb=[1,3:n];
for i=3:n
fibb(i)=fibb(i-1)*3+(i)-2;
end
diag(fibb)
  1 Comment
Ainars Cernavskis
Ainars Cernavskis on 19 Jul 2021
o it was that simple , thank you .

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 19 Jul 2021
n = input ('sequence_matrix_');
fibb = diag([1,3:n]);
for i=3:n
fibb(i,i) = fibb(i-1,i-1)*3+(i)-2;
end
fibb

Community Treasure Hunt

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

Start Hunting!

Translated by