101k views
5 votes
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

1 Answer

6 votes

Answer:

Using Matlab command

a)

displaying fourth row after generating a magic matrix of 6*6

%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 4th Row of Magic 6:');

disp(fourthRowMagic6);

b)

first we create a vector with values 0 --> 1.1 with increment of 0.1 and vector b with values 10 ----> 21 with increment of 1 value.

now

%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);

c)

randi[] fuction creates integer random values in given range.

% creates a random matrix of four rows and five columns varying between -8 and 9

r=randi([-8 9], 4,5);

disp('Here is a random 4 by 5 matrix varying between -8 and 9 ');

disp(r);

User Hisham Karam
by
5.3k points