creating a diagonal matrix?
Afficher commentaires plus anciens
Hi,
I want to create a diagonal matrix which has the elements like this: q1,q1,q2,q2,...,qm,qm
q is a function and has m different values for m different x-values
Could anyone help me please?
Thank you!
Réponses (3)
Simon
le 12 Déc 2013
Hi!
diag(q)
2 commentaires
FULYA SEREF
le 12 Déc 2013
Simon
le 13 Déc 2013
So, if you have your function q, what will be the output? Is it a m-element vector? Or just a scalar value?
If you have your m-element vector X, you can do
ind = 1:m;
ind = [ind; ind];
diag(X(ind(:)))
If you get scalars only you have to create it in a loop.
Sean de Wolski
le 12 Déc 2013
diag(q(1,2,3))
And for more info:
doc diag
1 commentaire
FULYA SEREF
le 12 Déc 2013
Jos (10584)
le 13 Déc 2013
Like this?
q = [10 20 30] ;
q = q(floor(1:.5:numel(q)+.5)) % expand (there are many other ways to do this!)
diag(q)
Catégories
En savoir plus sur Operating on Diagonal 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!