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

Need help with MATLAB questions please. I posted these questions two times and i

ID: 2258041 • Letter: N

Question

Need help with MATLAB questions please. I posted these questions two times and i got wrong answers both times. I need correct answers please

1) Generate a 2x2 random matrix with values taken from the interval [-1.5, 3.2].

2) Generate a 2x3 random integer matrix with values {0, 1} only and call it r1 and generate another 2x3 random integer matrix with values again taken from {0, 1} and call it r2. What can you say about the values in the position 2,2? Give the complete code to obtain the same matrix for r1 and r2 without simply assigning r1 to r2?

3) Generate a 10x20x30 random integer matrix called r3 values taken from the interval [-5, 15], but suppress (hide) the results using a proper Matlab command. Read the value at the r3_{7,12,10} position

4) The numbers from 0 to 2, spaced 0.1 apart (record the first few and the last few, and the command you used):

Explanation / Answer

1)

clc;
clear all;
close all;
for i=1:2
for j=1:2
r1(i,j)=(rand(1)-0.5)*2;
if r1(i,j)>0
r1(i,j)=r1(i,j)*3.2;
else
r1(i,j)=r1(i,j)*1.5;
end
end
  
end
fprintf('Generated random number matrix is :');
r1

OUTPUT:

Generated random number matrix is
:
r1 =

-1.2086 2.0701
1.2469 -0.5487

>>

2)

clc;
clear all;
close all;
for i=1:2
for j=1:3
r1(i,j)=(rand(1)-0.5)*2;  
if r1(i,j)>0
r1(i,j)=1;
else
r1(i,j)=0;
end
end
  
end
fprintf('Generated random number matrix r1 is : ');
r1
fprintf('value at (2,2) is %d ',r1(2,2));


for i=1:2
for j=1:3
r2(i,j)=(rand(1)-0.5)*2;  
if r2(i,j)>0
r2(i,j)=1;
else
r2(i,j)=0;
end
end
  
end
fprintf('Generated random number matrix r2 is : ');
r2
fprintf('value at (2,2) is %d ',r2(2,2));

%%% Generating r3 from r1
for i=1:2
for j=1:3
if r1(i,j)>0
r3(i,j)=1;
else
r3(i,j)=0;
end
end
end

OUTPUT:

Generated random number matrix r1 is :

r1 =

1 0 1
0 1 0

value at (2,2) is 1
Generated random number matrix r2 is :

r2 =

1 1 1
1 1 0

value at (2,2) is 1

3)

clc;
clear all;
close all;
r3=rand(10,20,30)*20-5;
fprintf('value at r3(7,12,10) = %f ',r3(7,12,30));

OUTPUT:

value at r3(7,12,10) = 8.591704

4)

clc;
clear all;
close all;
x=0:0.1:2;
fl=x(1:5); %%% starting few number
fh=x(end-5:end); %% ending few number
disp('starting few numbers are :');
fl
disp('ending few numbers are :');
fh

OUTPUT:

starting few numbers are :

fl =

0 0.1000 0.2000 0.3000 0.4000

ending few numbers are :

fh =

1.5000 1.6000 1.7000 1.8000 1.9000 2.0000

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote