I want to create a sparse matrix (121 by 121) with A repeating in the main diagonal.
I wrote a code below to create my 11 by 11 matrix A but how do i get a 121 by 121 sparse matrix with A repeating in the main diagonal.
n = 11;
D = sparse(1:n,1:n,-4*ones(1,n),n,n);
full(D);
E = sparse(2:n,1:n-1,ones(1,n-1),n,n);
E(11,10)=2;
full(E);
F = sparse(1:n-1,2:n,ones(1,n-1),n,n);
F(1,2)=2;
full(F);
S = E+D+F;
A=full(S)

 채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 23일

0 개 추천

temp = repmat({S}, 1, 11);
result = blkdiag(temp{:});

댓글 수: 1

SA
SA 2019년 4월 23일
It worked perfectly. Thanks a million

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

SA
2019년 4월 23일

댓글:

SA
2019년 4월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by