필터 지우기
필터 지우기

how to make the numbers on the matrix with alternative sign?

조회 수: 3 (최근 30일)
kingsley
kingsley 2017년 2월 15일
다시 열림: kingsley 2017년 2월 15일
I want to create a matrix that the main diagonal of K are alternatively 2 and -2’s, the sub- and sup-diagonal of K alternatively 1 and -1’s, and everywhere else 0. The size of K is 2n by 2n.
Here is what I got so far.
x=ones(1,5);
y=ones(1,4);
x2=2*x;
y2=y*-1;
z=diag(x2,0)
[rows, columns] = size(z)
z(1:2*rows+2:end) = -z(1:2*rows+2:end)
b=diag(y2,+1)
d=diag(y2,-1)
g=z+b+d

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by