How can I generate a matrix as in the picture?

1 Ansicht (letzte 30 Tage)
xiyou fu
xiyou fu am 11 Nov. 2016
Bearbeitet: Andrei Bobrov am 11 Nov. 2016
A is the matrix and n is an arbitrary number that larger than 3,thank you very much!

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 11 Nov. 2016
Bearbeitet: Andrei Bobrov am 11 Nov. 2016
n = 6; % Let n = 6
z = [-1 3 -3 1];
m = numel(z);
k = n-m+1;
A = full(spdiags(ones(k,1)*z,0:m-1,k,n));
other way with Communications System Toolbox:
n = 6; % Let n = 6
z = [-1 3 -3 1];
A = convmtx(z,n-numel(z)+1);

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 11 Nov. 2016
You can add together diag() calls
[diag(-1 * ones(1, n-3)), zeros(n-3,3)] + ...
[zeros(n-3, 1), diag(3 * ones(1, n-3)), zeros(n-3,2)] + ...
[zeros(n-3, 2), diag(-3 * ones(1, n-3)), zeros(n-3,1)] + ...
[zeros(n-3, 3), diag(1 * ones(1, n-3))]

Kategorien

Mehr zu Creating and Concatenating 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