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

In MATLAB, the command rand generates a single random number on [0, 1] according

ID: 2251837 • Letter: I

Question

In MATLAB, the command rand generates a single random number on [0, 1] according to the uniform law. Try it. The command rand(m, 1) generates a column vector of length m where each entry is generated independently according to the uniform law. Try it with m 37. If we set x (rand .32), the variable x will be either 0 (if the random number is greater than 0.32) or 1 (if the random number is less than .32). It shouldn't be hard to see that x = 1 with probability 0.32 and x = 0 with probability 0.68. Similarly, x = (rand (37, 1)

Explanation / Answer

% part (a)

prompt1 = 'enter the value of probability';

prompt2 = 'enter the number of throws';

p = input(prompt1);

N = input(prompt2);

function free_throws=FT(p,N)

FT=(rand(N,1) < p );

disp(FT);

For part (b) we need to sum up every 10 throws.. For each throw which goes into the basket the entry FT(i) will be 1. and for each where he misses FT(i) will be zero. So if we sum up consecutive 10 entries of FT(i) we must get atleast 5 as the answer. If the value of sum FT(i) is >= 5 then the given criteria is satisfied. But we will take a large enough sample space say 10000, to have an acceptable result. So now we will have to capture the sum FT(i) for every 10 free throws. And for 10000 free throws we will get 1000 such sets. Now out this 1000 sets the ones whiv have a value of sum FT(i) >= 5 will be recorded as a positive entry and we can use a counter to record the number of such sets. And then divide this counter value by 1000 to get the probability. for exqmple out of the 10000 free throws we get 1000 sets of 10 throws each, and say out of this 1000 sets 400 have a sum value of the set >= 5 then the probability of the condition being satisfied will be 400/1000=0.4.

Note: The more number of free throws we consider the more will be the accuracy. but also greater computation will be required. Also the probability p of putting the ball in the basket may be specified by the user to be anything that is different from 0.5 .

% First run the function freethrow for N=10000

for j = 1:(N/10), i = 1:10:N

SET(j) = sum(FT(i:i+9);

if SET(j) >= 5

count=count++;

end

end

prb = count/N; % probability of hitting 5 out of 10 consecutive free throws

disp(prb);

Similarly we can do part (c) and (d) for even larger sample space and taking sets of 100 and 1000 entries respectively.

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