2. Write the output matrix “v”
t = [2:4];
k = [1:3];
v = t.*k – k.^2
4. Given: D = [1 2 3 4 5 6 7 8 9] (3x3) . Which command will extract the submatrix [1 2 3 4 5 6] (2x3) ?
a. D[1:2,1:3]
b. D(1,2 ;1,3)
c. [D(1:2),D(1:3)]
d. D(1:2,1:3)
14. What will be the dimension of matrix B?
B=[ones(3) zeros(3) rand(3); 2*eye(9)]
18. Find the value of “C”
A=1:2:10;
B=linspace(1,5,5);
C = length(A)*B(2)+A(5)*B(3);
19. Matrix A is defined: A = [−1 2 −3 0 2 4 2 −2 3](3x3) Which command deletes the second row?
21. What is the value of C?: ______________________
A=[1 2 3;4 5 6; 7 8 9];
B=[1 3; 5 7];
C=sum(B(:,1)+A(1:2,2));
22. What is the value of C?:
A=[1 2 3;4 5 6; 7 8 9];
B=[1 3; 5 7];
D=B(1,:).*A(2,2:3);
25. Using “subplot(m,n,p)” command create a figure window which will plot x ∙ sin(x) and cos(x+2), side by side in the same figure window. The vector x ∈ [−pi, pi], has 50 elements. x=___________________________;
subplot(____________); _________________________
subplot(____________); _________________________
Answer 2: v = [1 2 3]
//v is a 1x3 matrix
Answer 4: option d D(1:2,1:3)
Answer 14: dimensions of B are [12x9]
Answer 18: value of C is 37
Answer 19: A(2,:) = [ ]
%empty square brackets, above command delets the second row of matrix A
Answer 21 : value of C is 13
Answer 22: value of D is D = [5 18] (1x2)
Answer 25: x = linspace(-pi,pi,50);
%generates vector of 50 values from -pi to pi
y1 = sin(x);
y2 = cos(x+2);
grid on
subplot(1,2,1); %plots sin(x) graph
plot(x,y1);
subplot(1,2,2); %plots cos(x+2) graph
plot(x,y2);
title('sin(x) and cos(x+2)');
Get Answers For Free
Most questions answered within 1 hours.