Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB CODE please 4, (2006) Write a program that will perform the following a.

ID: 3721350 • Letter: M

Question

MATLAB CODE please

4, (2006) Write a program that will perform the following a. Define 2 by 7 array contains random numbers in the interval -10 to 10 b. Print the array c. The first row of the array represents the real part and the second row the imaginary part of a complex numbers Define another 2 by 7 array and fill the first row wit and the second row with their angle d. h the magnitude of the corresponding complex numbers e. Print the array f. Find the number that has the maximum magnitude. Print its magnitude, its angle and its location in the table (20%) Write a program that will perform the followings a. Accept a number, n, from the user in the interval 5 to 8 b. Define a square array n by rn c. Fill the array with random integer numbers in the interval 0.0 to 10.00 d. Print the array e. Switch the numbers in the second row with the numbers in the last row f. Print the resulted array g. Then switch the number in the second column with the numbers in the last column h. Print the resulted array 5,

Explanation / Answer

4th question

a=-10;

b=10;

r = (b-a).*rand(2,7) + a;

t1=sprintf('random array is ');

disp(t1);

disp(r);

m1=sqrt((power(r(1),2)+power(r(8),2)));

m2=sqrt((power(r(2),2)+power(r(9),2)));

m3=sqrt((power(r(3),2)+power(r(10),2)));

m4=sqrt((power(r(4),2)+power(r(11),2)));

m5=sqrt((power(r(5),2)+power(r(12),2)));

m6=sqrt((power(r(6),2)+power(r(13),2)));

m7=sqrt((power(r(7),2)+power(r(14),2)));

p1=atan2(r(8),r(1));

p2=atan2(r(9),r(2));

p3=atan2(r(10),r(3));

p4=atan2(r(11),r(4));

p5=atan2(r(12),r(5));

p6=atan2(r(13),r(6));

p7=atan2(r(14),r(7));

x=[m1,m2,m3,m4,m5,m6,m7;p1,p2,p3,p4,p5,p6,p7];

t2=sprintf(' array with magnitudes and angles is ');

disp(t2);

disp(x);

m=max(x,[],2);

M=max(m);

t3=sprintf('highest magnitude is ');

disp(t3);

disp(M);

I=find(x==M);

t4=sprintf('index of highest magnitude is ');

disp(t4);

disp(I);

P=x(I+1);

t5=sprintf('angle of highest magnitude is ');

disp(t5);

disp(P);

5th question

a=5;

b=8;

n=(b-a).*rand(1,1) + a;

n=round(n);

t1=sprintf('order of array');

disp(t1);

disp(n);

x=0.0;

y=10.00;

t2=sprintf('square matrix is');

disp(t2);

s=(y-x).*rand(n,n) + x;

disp(s);

%swapping rows

copy_s=s(:,:);

copy_s1=s(:,:);

copy_s1(n,:)=copy_s(2,:);

copy_s1(2,:)=copy_s(n,:);

t3=sprintf('after swapping rows');

disp(t3);

disp(copy_s1);

%swapping columns

copy_s2=s(:,:);

s(:,n)=copy_s2(:,2);

s(:,2)=copy_s2(:,n);

t4=sprintf('after swapping columns');

disp(t4);

disp(s);