如何创建这样的矩阵
A = [a 0 0 0 0 b;
0 a 0 0 b 0;
0 0 a b 0 0;
0 0 b a 0 0;
0 b 0 0 a 0;
b 0 0 0 0 a]
答案 0 :(得分:3)
也许是这样的
N = 6; % Size of matrix
a = 1; % Example value
b = 2; % Example value
A = a*eye(N) + b*fliplr(eye(N));
A =
1 0 0 0 0 2
0 1 0 0 2 0
0 0 1 2 0 0
0 0 2 1 0 0
0 2 0 0 1 0
2 0 0 0 0 1