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

Please show step-by-step what to enter in MATLAB. I have never used MATLAB. Crea

ID: 2989555 • Letter: P

Question

Please show step-by-step what to enter in MATLAB. I have never used MATLAB.

Create the following matrix A = in MATLAB. Define a vector Al containing the first row of A. Define a scalar, smmAl, equal to the sum of its elements. Create a vector sumRows where each element corresponds to the some of the elements in that row, try to implement it using a single command. Please turn in your MATLAB code and the output for each step. 5. Use the MATLAB randi function to simulate the toss of a coin. (do help randi to learn more about the function). Find the percentage of heads occurring in a fair coin tossed 50, 100, 1000 and a minion times. Rim in your MATLAB code and the outputs.

Explanation / Answer

4)

A=[16 3 2 13;5 10 11 8;9 6 7 12;4 15 14 1] % this will create the matrix

A1=A(1,:) % this wil give the first row of A.

sumA1=sum(A1) % this will give the sum of elements of A1

sumRows=sum(A,2) % it will calculate the sum of rows.

5)

n=0;
step1=50; % you want to toss the coin for 50 times
for i=1:step1 % the loop will run for 50 times
r=randi(2,1); % it'll create a random number between 1 and 2.lets consider when r=1 it's head and when r=2 it's tail
if r==1 % so when r is 1, this loop will start
n=n+1; % and increase the value of n by 1.
end
end
head1= (n/step1)*100; % it will give percentage of occurance of random number 1 i.e occuring head.

m=0;
step2=100;
for i=1:step2
r=randi(2,1);
if r==1
m=m+1;
end
end
head2= (m/step2)*100;

p=0;
step3=10^6;
for i=1:step3
r=randi(2,1);
if r==1
p=p+1;
end
end
head3= (p/step3)*100;
fprintf('Percentage of head occured for 50 toss: %0.2f ',head1);
fprintf('Percentage of head occured for 100 toss: %0.2f ',head2);
fprintf('Percentage of head occured for million toss: %0.2f ',head3);