Search code examples
matlabmatrixlinear-algebradeterminants

How to find determinants for four matrices


A=[1 2;3 4];
B=[5 6;7 8];
C=[8 7;6 5];
D=[4 3;2 1];

E=[det(A(1) B(1);C(1) D(1)) det(A(2) B(2);C(2) D(2));det(A(3) B(3);C(3) D(3)) det(A(4) B(4);C(4) D(4))]

I want to get a matrix which equals E.

If A B C D are very large, this is cumbersome to write by hand. How can I do this automatically?


Solution

  • Provided A, B, C, and D, get large, but not more matrices are added to this list, the following should do:

    A = rand(20);
    B = rand(20);
    C = rand(20);
    D = rand(20);
    E = zeros(size(A)); % initialise E as big as the others
    for ii = 1:numel(A) % loop over linear indices
        E(ii) = det([A(ii) B(ii);C(ii) D(ii)]); % build determinant
    end