On Fri, 13 Dec 2013, Qi Shi wrote:
Dear all,
how to transform a square matrix to a diagonal matrix using commands? for
example, we have A={2,1;1,3}, how can I get a matrix B={2,0;0,3}?
For example
<hansl>
n = rows(A)
B = zeros(n,n)
B[diag] = A[diag]
<hansl>
or
<hansl>
B = I(rows(A)) ? A : 0
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------