Please use MatLab to do the following question Consider an e

Please use MatLab to do the following question:

Consider an experiment of tossing a biased coin n = 100 times and recording the number of heads. Let the probability of heads be p = 0.7. Create a function that returns a vector of t = 10000 trials of the experiment. The signature of the function should be

trials = function(n, t, p).

Solution

function [ result ] = trials(n ,t , p)
    result = zeros( t , 1);
    for trialNo = 1:t
        noOfHeads = 0;
        for toss = 1:n
            x=rand;
            if x< p
              select=1;
            else
              select=0;
            end
            noOfHeads = noOfHeads + select;
        end
        result(trialNo) = noOfHeads;
    end
end

Please use MatLab to do the following question: Consider an experiment of tossing a biased coin n = 100 times and recording the number of heads. Let the probabi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site