Question: MATLAB! Write a MATLAB function that simulates a single roll of a n-sided die. The inputsand outputs of the function are: Inputs: The probabilities for

MATLAB!

Write a MATLAB function that simulates a single roll of a n-sided die.

The inputsand outputs of the function are:

Inputs:

The probabilities for each side, given as a vector p = [p1,p2...pn]

Outputs:

The number onthe face of the die after a single roll, i.e.onenumber fromthe setof integers

{1, 2 ,....n}

Note: The sum p1+p2+.....pn must be equal to 1.0, otherwise the probability values are incorrect.

Savethe function as: nsided_die(p)

Test the functionwitha 5-sided die,where theprobabilitiesaregiven by the vector p=[0.10, 0.25, 0.30, 0.15, 0.20]

To test the function, roll the die for N=10,000times and plot the outcome as a stem plot.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!