hi, i would like to get some help with defining the next matrix in the easiest way. i know the diag() function but i didnt find a way the define the non-main diagonals.

 채택된 답변

Stephen23
Stephen23 2021년 8월 4일

1 개 추천

N = 7;
M = toeplitz([-2,1,zeros(1,N-2)])
M = 7×7
-2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2

댓글 수: 2

Nitzan Haviv
Nitzan Haviv 2021년 8월 4일
thanks a lot!
Stephen23
Stephen23 2021년 8월 4일
@Nitzan Haviv: my pleasure! Remember to click the accept button if my answer helped you!

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

추가 답변 (1개)

Nitzan Haviv
Nitzan Haviv 2021년 8월 4일

0 개 추천

btw i found another way
when N is the dimention of the square matrix
d_sec = ones(1,N-1);
d_main= ones(1,N).*-2;
H = diag(d_main)+diag(d_sec,-1) + diag(d_sec,1);

카테고리

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

제품

태그

질문:

2021년 8월 4일

답변:

2021년 8월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by