You are on page 1of 2

Exercise 4- Past exam questions solution

Q1. Write a MATLAB script file (yourfirstname_Q1.m) to create the following matrix A:

[ ]
1.1 −3.2 3.4 0.6
A= 0.6 1.1 −0.6 3.1
1.3 0.6 5.5 0

>>A=[1.1 -3.2 3.4 0.6; 0.6 1.1 -0.6 3.1;1.3 0.6 5.5 0];
- Write a MATLAB code to find the maximum and minimum values in each column of
Matrix A.
>>max(A)
>>min(A)
- Write a MATLAB code to find the maximum and minimum values in each row of Matrix
A.
>>max(A’)
>>min(A’)
- Write a MATLAB code to sum all of values in each row of Matrix A.
>>sum(A)
- Write a MATLAB code to sum all of values in Matrix A.
>>sum(sum(A))
- Write a MATLAB code to obtain the subset C taken directly from Matrix A where

C=
[−3.2
0.6 ]
>>A([1 3],2)
- Write a MATLAB code to obtain the maximum value from all rows and columns of
Matrix A
>>max(A(:))
Q2. Create yourfirstname_Q2.m. In this file, write MATLAB code to compute and display the
smallest non-negative integer n such that 2n >a . Known that a is the number that input from
keyboard. Test with the case a=1; value of n should be displayed as 0.
a=input(“input the non-negative value:”)
n=0;
while 2^n<=a
n=n+1;
end
n

You might also like