How can I create a matlab matrix below?

조회 수: 1 (최근 30일)
kimjandi
kimjandi 2021년 3월 3일
답변: Walter Roberson 2021년 3월 3일
Hi, I've been wanting to construct a matlab matrix that is n by n. and looks like this. I've beeen trying to use diag but the function diag doesn't provide this. so m a bit confused. Please help!

채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 3일
N = 6;
diag(-2*ones(1,N)) + diag(ones(1,N-1),-1) + diag(ones(1,N-1),1)
ans = 6×6
-2 1 0 0 0 0 1 -2 1 0 0 0 0 1 -2 1 0 0 0 0 1 -2 1 0 0 0 0 1 -2 1 0 0 0 0 1 -2

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by