Given an nxn matrix A, how do I produce a lower triangular matrix with ones on the diagonal?

1 visualización (últimos 30 días)
Given an nxn matrix A, how do I produce a lower triangular matrix with ones on the diagonal?
I tried
A = rand(n,n);
L = tril(A,1) + diag(ones(1, size(A,1))) ;
but it isn't working.

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 23 de Sept. de 2019
tril(A,-1)+eye(n)

Categorías

Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by