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

1 vue (au cours des 30 derniers jours)
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.

Réponses (1)

Fangjun Jiang
Fangjun Jiang le 23 Sep 2019
tril(A,-1)+eye(n)

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by