Getting a diag function
4 ビュー (過去 30 日間)
古いコメントを表示
Hi there im stuck with this problem and really would like help here
n=length(x) %Let says is 20
x=rand(n,1);
y=rand(n,1);
RHS_empty=ones(ny,1);
iter_h=0;
for i=1:n-1
h(i)=x(i+1)-x(i);
iter_h=iter_h+1;
Ma_Sp=diag(1 h(i)) 2(h(i+1)*h(i))
end
I like to create a diagonal matrix with the interval with the specific things,
The diagonal matrix size is depending on the h(i), meaning h19, i like to get the matrix to be 20x20 with 1 at the first lane and h1 2h2*h1 h2 2h3*h2 hn 2h(i+1)*h(i) for the second coloum and it goes on for the third coloum and the fourth all the way to the 20th column, i am stuck on this matter and would appreciate your help
3 件のコメント
Jan
2021 年 3 月 18 日
編集済み: Jan
2021 年 3 月 18 日
The shown matrix A is not diagonal. Diagonal matrices contaoin non-zero elements on the diagonal only. You can create them with the command diag() .
There is a large, if not infitine number of ways, to fill a 20x20 matrix with a 4x4 matrix.
Maybe you are looking for the kron() command:
x = [1,2;3,4]
x =
1 2
3 4
kron(eye(3), x)
ans =
1 2 0 0 0 0
3 4 0 0 0 0
0 0 1 2 0 0
0 0 3 4 0 0
0 0 0 0 1 2
0 0 0 0 3 4
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!