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