How to create a diagonal matrix that starts at (1,1)?

6 ビュー (過去 30 日間)
Renea Young
Renea Young 2021 年 11 月 21 日
回答済み: Star Strider 2021 年 11 月 21 日
Can someone help me?
How do I create a diagonal matrix of lambda, where lambda = 0.2? I would like the diagonal to start at (1,1).
Any help would be greatly appreciated.
  3 件のコメント
Jan
Jan 2021 年 11 月 21 日
What is the wanted output? Which dimension should the output have?
Renea Young
Renea Young 2021 年 11 月 21 日
The output should be A = [0 0 0 0 0 ....0;0 0.200 0 0 0 .....0;0 0 0.200 0 0...0; 0 0 0 0.200 0 ....0]
The dimension is N

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2021 年 11 月 21 日
Without using repmat
n = 4;
lambda = 0.2;
A = diag([0 ones(1,n)]*lambda)
A = 5×5
0 0 0 0 0 0 0.2000 0 0 0 0 0 0.2000 0 0 0 0 0 0.2000 0 0 0 0 0 0.2000
,

その他の回答 (2 件)

Jan
Jan 2021 年 11 月 21 日
Maybe you mean:
n = 4;
lambda = 0.2;
A = eye(n) * lambda
A = 4×4
0.2000 0 0 0 0 0.2000 0 0 0 0 0.2000 0 0 0 0 0.2000
% Or:
A = diag(repmat(lambda, 1, n))
A = 4×4
0.2000 0 0 0 0 0.2000 0 0 0 0 0.2000 0 0 0 0 0.2000

Walter Roberson
Walter Roberson 2021 年 11 月 21 日
n = 4;
lambda = 0.2;
A = diag(repmat(lambda, 1, n), 1)
A = 5×5
0 0.2000 0 0 0 0 0 0.2000 0 0 0 0 0 0.2000 0 0 0 0 0 0.2000 0 0 0 0 0

カテゴリ

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