EMAE 250 – Computers in Engineering
Lab #2 – Determinant of 4 × 4 Matrix – Pre-lab – Linear Program
big = 0;
% next for loop iteration
term = A(1,2);
% start for loop
F = A;
term = A(1,1);
F(1,:) = [];
B = A;
F(:,2) = [];
B(1,:) = [];
small = 0;
B(:,1) = [];
term2 = F(1,1);
small = 0;
G = F;
term2 = B(1,1);
G(1,:) = [];
C = B;
G(:,1) = [];
C(1,:) = [];
det_G = (G(1,1)*G(2,2) G(1,2)*G(2,1));
C(:,1) = [];
det_C = (C(1,1)*C(2,2) C(1,2)*C(2,1));
small = small + term2*det_G;
small = small + term2*det_C;
H = F;
term2 = B(1,2);
H(1,:) = [];
D = B;
H(:,2) = [];
D(1,:) = [];
D(:,2) = [];
det_H = (H(1,1)*H(2,2) H(1,2)*H(2,1));
det_D = (D(1,1)*D(2,2) D(1,2)*D(2,1));
small = small - term2*det_H;
term2 = F(1,3);
small = small - term2*det_D;
J = F;
term2 = B(1,3);
J(1,:) = [];
E = B;
J(:,3) = [];
E(1,:) = [];
det_J = (J(1,1)*J(2,2) J(1,2)*J(2,1));
E(:,3) = [];
det_E = (E(1,1)*E(2,2) E(1,2)*E(2,1));
term2 = F(1,2);
small = small + term2*det_J;
big = big - term*small;
small = small + term2*det_E;
big = big + term*small;
Pre-lab #2
EMAE 250
Pg. 1
% next for loop iteration
% next for loop iteration
term = A(1,3);
term = A(1,4);
K = A;
P = A;
K(1,:) = [];
P(1,:) = [];
K(:,3) = [];
P(:,4) = [];
small = 0;
small = 0;
term2 = K(1,1);
term2 = P(1,1);
L = K;
Q = P;
L(1,:) = [];
Q(1,:) = [];
L(:,1) = [];
Q(:,1) = [];
det_L = (L(1,1)*L(2,2) L(1,2)*L(2,1));
det_Q = (Q(1,1)*Q(2,2) –
Q(1,2)*Q(2,1));
small = small + term2*det_L;
small = small + term2*det_Q;
term2 = K(1,2);
term2 = P(1,2);
M = K;
R = P;
M(1,:) = [];
R(1,:) = [];
M(:,2) = [];
R(:,2) = [];
det_M = (M(1,1)*M(2,2) M(1,2)*M(2,1));
det_R = (R(1,1)*R(2,2) R(1,2)*R(2,1));
small = small - term2*det_M;
small = small - term2*det_R;
term2 = K(1,3);
term2 = P(1,3);
N = K;
S = P;
N(1,:) = [];
S(1,:) = [];
N(:,3) = [];
S(:,3) = [];
det_N = (N(1,1)*N(2,2) N(1,2)*N(2,1));
det_S = (S(1,1)*S(2,2) S(1,2)*S(2,1));
small = small + term2*det_N;
small = small + term2*det_S;
big = big + term*small;
big = big - term*small;
Pre-lab #2
EMAE 250
Pg. 2