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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started