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

1 Ansicht (letzte 30 Tage)
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.

Antworten (1)

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

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by