Matrix form

조회 수: 6 (최근 30일)
Feruz
Feruz 2011년 12월 8일
Hi,
I have a question about make a matrix which has form of
Let say I have
cel = spdiags(ones(N,1),1,N,N) - spdiags(ones(N,1),-1,N,N);
N is size in a sense that matrix size is N^3 by N^3, and first N by N part, and then N^2 by N^2 part and then N^3 by N^3 matrices super-diagonals are 1 and -1, main diagonal is 0. I hope it makes sense!
So NxN zero main diag, and from N+1,N+1 starts again same matrix till N^2xN^2, then from N^2+1,N^2+1 starts again same matrix till N^3xN^3
I have tried with kron function, which is obvious function to use, i.e.
full(kron(speye(N),cel))
but unable to create very same matrix
Let say I have this scheme in 3D, boundary conditions are zero on the boundary
(u_i,j,k+1 - u_i,j,k-1)/(2*h) => which gives my matrix A
and I have vector u = [u_111,u_112,u_121,u_122,u_211,u_212,u_221,u_222] then I have Au = b where b is any vector size of 8...
Thanks in advance!

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2011년 12월 8일
s = N.^(1:3);
bs = arrayfun(@(x)spdiags(ones(x,1)*[-1 1],[-1 1],x,x),s,'un',0);
out = blkdiag(bs{:});
  댓글 수: 1
Feruz
Feruz 2011년 12월 8일
Thank you for reply,
But I guess I did explain it not the way I should...
Let say I have this scheme in 3D, boundary conditions are zero on the boundary
(u_i,j,k+1 - u_i,j,k-1)/(2*h) => which gives my matrix A
and I have vector u = [u_111,u_112,u_121,u_122,u_211,u_212,u_221,u_222] then I have Au = b
where b is any vector size of 8...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by