Make Sequence Function go Diagonal

1 vue (au cours des 30 derniers jours)
Ainars Cernavskis
Ainars Cernavskis le 19 Juil 2021
Commenté : Rena Berman le 27 Nov 2023
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
  2 commentaires
Sam Chak
Sam Chak le 23 Nov 2023
The original question may be beneficial for people who wish to learn how to create a diagonal matrix.
Rena Berman
Rena Berman le 27 Nov 2023
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponse acceptée

Sameer Pujari
Sameer Pujari le 19 Juil 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 commentaire
Ainars Cernavskis
Ainars Cernavskis le 19 Juil 2021
o it was that simple , thank you .

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 19 Juil 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

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by