Create program code for a function coin “coin toss” that simulates “n” coin toss and returns the vector “v” with the result of the coin toss, together with the number “quantity of Coins” which indicates how many of the coin tosses in “v” resulted in the page ” coin”.

A coin toss (‘mk’) can be simulated with the code line mk = randi (2,1); , where we interpret the value 1 as the page “crown”, and the value 2 as the page “coin” (so this code line gives us (randomly) one of the numbers in the set {1,2}).

  1. A) Create program code for a function coin “coin toss” that simulates “n” coin toss and returns the vector “v” with the result of the coin toss, together with the number “quantity of Coins” which indicates how many of the coin tosses in “v” resulted in the page ” coin”. Your code should begin with

function [v, quantity Coin] = coin toss (s)

 

  1. B) Use the function you wrote in problem A) to simulate n = 100-coin toss. Write a program that counts the quantity of simulated coin tosses before the first “crown” occurs. Suggest a “reasonable” value for the case where since “crown” is not observed in the n coin tosses.
Create program code for a function coin “coin toss” that simulates “n” coin toss and returns the vector “v” with the result of the coin toss, together with the number “quantity of Coins” which indicates how many of the coin tosses in “v” resulted in the page ” coin”.
Scroll to top