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

1 回表示 (過去 30 日間)
Emily Gallagher
Emily Gallagher 2019 年 9 月 23 日
回答済み: Fangjun Jiang 2019 年 9 月 23 日
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.

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2019 年 9 月 23 日
tril(A,-1)+eye(n)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by