필터 지우기
필터 지우기

How can i describe this matrix of the size M by M by using ''spdiags command'' ?

조회 수: 1 (최근 30일)
Taha Mohammed
Taha Mohammed 2023년 10월 9일
답변: Walter Roberson 2023년 10월 10일
  댓글 수: 2
John D'Errico
John D'Errico 2023년 10월 9일
What have you tried? If nothing, why not?
You clearly know what function you need to use. The diagonals are trivial to generate, since there are only two of them, and the matrix is constant down those diagonals. So why not take a shot, and then show what you tried?
Walter Roberson
Walter Roberson 2023년 10월 9일
Four diagonals, actually, considering the top right and bottom left.

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

답변 (1개)

Walter Roberson
Walter Roberson 2023년 10월 10일
Hint:
init = repmat((1:6).',1,2)+[0 10]
init = 6×2
1 11 2 12 3 13 4 14 5 15 6 16
full(spdiags(init, [-4 4], spalloc(6,6,0)))
ans = 6×6
0 0 0 0 15 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 2 0 0 0 0
So negative diagonals take elements from the top of the initialization matrix, and positive diagonals take elements from the bottom of the initialization matrix.

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by