To determine the probability of a d20 die landing an even number divisible by 4 in matlab
, we can use the concept of probability distribution.
Here's the code to calculate the probability of a d20 die landing an even number divisible by 4:
main.m298 chars9 lines
Here, we first define the probability distribution for a d20 die using an anonymous function. This function returns a probability of 1/20
for each outcome between 1
and 20
.
Next, we define the event that we're interested in using another anonymous function. This function returns true
for outcomes that are both even and divisible by 4.
We then calculate the probability of this event using the integral
function. This function integrates the product of the event and distribution functions over an infinite range to give us the probability of the event occurring.
The probability
variable will contain the probability of a d20 die landing an even number divisible by 4.
gistlibby LogSnag