Exercise 1 Use Matlab command to obtain the following a Extr
Exercise 1: Use Matlab command to obtain the following
a) Extract the fourth row of the matrix generated by magic(6)
b) Show the results of ‘x’ multiply by ‘y’ and ‘y’ divides by ‘x’. Given x = [0:0.1:1.1] and y = [10:21]
c) Generate random matrix ‘r’ of size 4 by 5 with number varying between -8 and 9
Solution
1.Generate a magic matrix of 6*6 and then display fourth row.
%generate matrix magic(6)
magic6= magic(6);
disp(\'This is Magic(6): \');
disp(magic6);
%Obtain the fourth row elements of magic6
fourthRowMagic6=magic6(4,:);
disp(\'This is the fourth Row of Magic 6: \');
disp(fourthRowMagic6);
------------------------------------
2.
create a vector with values 0 to 1.1 with increment of 0.1 and vector b with values 10 to 21 with increment of 1 value.
%creating and array x
x=[0:0.1:1.1];
y=[10:21];
%x multiply by y
multip_xy= x.*y;
%y divide by x
div_yx=y./x;
%display Text
disp(\'x: \');
disp(x);
disp(\'y: \');
disp(y);
disp(\'Multiplication of \'\'x\'\' and \'\'y\'\' is: \');
disp(multip_xy);
disp(\'Division of \'\'y\'\' and \'\'x\'\' is: \');
disp(div_yx);
===========================
3.randi[] fuction creates integer random values in given range.
%creates a ramdom matrix of 4 rows and 5 colunms varying between -8 and 9
r=randi([-8 9], 4,5);
disp(\'Here is a ramdom 4 by 5 matrix varying between -8 and 9 \');
disp(r);
