Index an array using specific indices
0 Comments
Answers (4)
1 Comment
3 Comments
a = input('Rows for x1: '); b = input('Columns for x1: '); x1 = zeros(a,b); for i = 1:a for j = 1:b x1(i,j) = input('Enter elements for x1: '); end end
c = input('Rows for x2: '); d = input('Columns for x2: '); x2 = zeros(c,d); for i = 1:c for j = 1:d x2(i,j) = input('Enter element for x2: '); end end
disp('Matrix x1:'); disp(x1) disp('Matrix x2:'); disp(x2)
% Step 1: Create two 3x3 matrices x1 = [1 2 3; 4 5 6; 7 8 9]; % you can replace with your own values x2 = [9 8 7; 6 5 4; 3 2 1]; % you can replace with your own values
% Step 2: Perform the required operations
% a) y1 = x1 - 2x2 y1 = x1 - 2*x2;
% b) y2 = 3x2 + (1/2)x1 y2 = 3*x2 + 0.5*x1;
% c) y3 = (2/3)x1x2 (matrix multiplication) y3 = (2/3) * (x1 * x2);
% d) y4 = x2x1 (matrix multiplication) y4 = x2 * x1;
% e) y5 = x1^(-4) + x2^3 % x1^(-4) means inverse(x1)^4, must be invertible try y5 = (inv(x1)^4) + (x2^3); catch disp('Matrix x1 is not invertible, choose another set of values.'); y5 = NaN; end
% Display results disp('y1 ='); disp(y1); disp('y2 ='); disp(y2); disp('y3 ='); disp(y3); disp('y4 ='); disp(y4); disp('y5 ='); disp(y5);
0 Comments
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!