How to create a special diagonal matrix with 2 vectors together?
3 ビュー (過去 30 日間)
古いコメントを表示
my problem is those vectors are given,but you have to put them like image shown below I dont know how to change the dimension of B so that it can fit into the matrix A = linspace(1,6,6) B = linspace(11,16,6) P.S the question asked us to use diag...
4 件のコメント
Stephen23
2018 年 1 月 30 日
Also, I want to know the way to use loop. So you could deal with both scalar and vector example for a and b...
採用された回答
Walter Roberson
2018 年 1 月 30 日
hint 1:
diag(b(1:end-1), -1)
hint 2: you can add matrices together.
5 件のコメント
その他の回答 (1 件)
Andrei Bobrov
2018 年 1 月 30 日
編集済み: Andrei Bobrov
2018 年 1 月 30 日
full(gallery('tridiag',B(2:end),A,B(1:end-1)));
or
n = numel(A);
out = full(spdiags([B(:),A(:),B(:)],-1:1,n,n)');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
