Filter löschen
Filter löschen

how to create a diagonal matrix with the semibandwidth of 4

2 Ansichten (letzte 30 Tage)
LIN Hongbin
LIN Hongbin am 2 Jan. 2017
Kommentiert: LIN Hongbin am 3 Jan. 2017
how to create a matrix like this:

Akzeptierte Antwort

Niels
Niels am 2 Jan. 2017
Bearbeitet: Niels am 2 Jan. 2017
Hi Lin Hongbin
not sure if your picture contains some errors, A(3,1) looks suspicious to me...
look at this and tell me if it fits your wishes :)
a=1:10;
b=11:20;
c=21:30;
d=31:40;
n=length(a);
A=zeros(n);
% set the rest
for i=1:n % rows
A(i,i:i+3)=[a(i),b(i),c(i),d(i)];
end
>> A
A =
1 11 21 31 0 0 0 0 0 0 0 0 0
0 2 12 22 32 0 0 0 0 0 0 0 0
0 0 3 13 23 33 0 0 0 0 0 0 0
0 0 0 4 14 24 34 0 0 0 0 0 0
0 0 0 0 5 15 25 35 0 0 0 0 0
0 0 0 0 0 6 16 26 36 0 0 0 0
0 0 0 0 0 0 7 17 27 37 0 0 0
0 0 0 0 0 0 0 8 18 28 38 0 0
0 0 0 0 0 0 0 0 9 19 29 39 0
0 0 0 0 0 0 0 0 0 10 20 30 40
if u cut off the first and last column it looks more like your picture (beside A(3,1) and A(3,4) etc is not d3 ...)
B=A(1:n,2:n+2)
B =
11 21 31 0 0 0 0 0 0 0 0
2 12 22 32 0 0 0 0 0 0 0
0 3 13 23 33 0 0 0 0 0 0
0 0 4 14 24 34 0 0 0 0 0
0 0 0 5 15 25 35 0 0 0 0
0 0 0 0 6 16 26 36 0 0 0
0 0 0 0 0 7 17 27 37 0 0
0 0 0 0 0 0 8 18 28 38 0
0 0 0 0 0 0 0 9 19 29 39
0 0 0 0 0 0 0 0 10 20 30
so either matrix A or B might be the answer.
But neither A nor B are quadratic. A has size n x n+3 and B: n x n+1
  3 Kommentare
LIN Hongbin
LIN Hongbin am 3 Jan. 2017
Thank you Niels, you did help me solve this problem.Appreciate you a lot.
LIN Hongbin
LIN Hongbin am 3 Jan. 2017
The answer in your comment is what I want.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by