Alix Wonder
Alix Wonder

Reputation: 33

How to create a criss cross diagonal matrix

How to create a matrix like this

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]  

Upvotes: 3

Views: 149

Answers (1)

NLindros
NLindros

Reputation: 1693

Perhaps something like this

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

Upvotes: 3

Related Questions