Use MATLAB to solve following question parts. Each part should
have a separate MATLAB
script (.m file, example: Q3a.m, Q3b.m, etc). Run each part and answers you get, write them in
the file using a word processor. You should also submit the scripts.
Given matrices A , B, C and D defined by:




Find:
a. The sum of A and B and assign answer to sum. What is the value of sum?
b. Product of A and B and assign answer to prod. What is the value of prod.
c. Determinant of A and assign answer to detA. What is the value of detA?
d. Inverse of B and assign answer to invB. What is the value of invB?
e. B(C-3D) and assign answer to M. What is the value of M?
Solution:
(a). Matlab Code for Q3a.m script:
% Assign matrices A and B
A = [1 3 2; 3 3 0; 2 0 4];
B = [0 2 1; -2 0 3; -1 3 0];
% Assign sum of A and B to Sum
Sum = A+B;
disp(Sum);
(b). Matlab Code for Q3b.m script:
% Assign matrices A and B
A = [1 3 2; 3 3 0; 2 0 4];
B = [0 2 1; -2 0 3; -1 3 0];
% Assign product of A and B to Prod
Prod = A*B;
disp(Prod);
(c). Matlab Code for Q3c.m script:
% Assign matrix A
A = [1 3 2; 3 3 0; 2 0 4];
% Assign determinant of A to detA
detA = det(A);
disp(detA);
(d). Matlab Code for Q3d.m script:
% Assign matrix B
B = [0 2 1; -2 0 3; -1 3 0];
% Assign inverse of B to invB
invB = inv(B);
disp(invB);
(e). Matlab Code for Q3e.m script:
% Assign matrices B, C and D
B = [0 2 1; -2 0 3; -1 3 0];
C = [1; 0; 2];
D = [3; 1; 2];
% Assign B(C-3D) to M
M = B*(C-(3*D));
disp(M);
script (.m file, example: Q3a.m, Q3b.m, etc). Run each part and answers you get, write them in
the file using a word processor. You should also submit the scripts.
Given matrices A , B, C and D defined by:




Find:
a. The sum of A and B and assign answer to sum. What is the value of sum?
b. Product of A and B and assign answer to prod. What is the value of prod.
c. Determinant of A and assign answer to detA. What is the value of detA?
d. Inverse of B and assign answer to invB. What is the value of invB?
e. B(C-3D) and assign answer to M. What is the value of M?
Solution:
(a). Matlab Code for Q3a.m script:
% Assign matrices A and B
A = [1 3 2; 3 3 0; 2 0 4];
B = [0 2 1; -2 0 3; -1 3 0];
% Assign sum of A and B to Sum
Sum = A+B;
disp(Sum);
(b). Matlab Code for Q3b.m script:
% Assign matrices A and B
A = [1 3 2; 3 3 0; 2 0 4];
B = [0 2 1; -2 0 3; -1 3 0];
% Assign product of A and B to Prod
Prod = A*B;
disp(Prod);
(c). Matlab Code for Q3c.m script:
% Assign matrix A
A = [1 3 2; 3 3 0; 2 0 4];
% Assign determinant of A to detA
detA = det(A);
disp(detA);
(d). Matlab Code for Q3d.m script:
% Assign matrix B
B = [0 2 1; -2 0 3; -1 3 0];
% Assign inverse of B to invB
invB = inv(B);
disp(invB);
(e). Matlab Code for Q3e.m script:
% Assign matrices B, C and D
B = [0 2 1; -2 0 3; -1 3 0];
C = [1; 0; 2];
D = [3; 1; 2];
% Assign B(C-3D) to M
M = B*(C-(3*D));
disp(M);
No comments:
Post a Comment