Welcome to this third lecture on matlab and probability. In this lecture we’re going stray from your typical probability course. So we’re going to have some data matrix, and we’re going to measure the probability of a variable that the data matrix represents. So what I want you to do is I want you to go to in your web browser github.com/lazyprogrammer/matlab-probability-class. Once you go there, you’re going to copy and paste this SSH clone URL, and I want you to go into your terminal and type in and git clone, and then paste that URL. I’ve already done it so I’m not going to do it again. This is going to give you some files that are relevant to this class that I’m going to use for the coming lectures. Okay, so, now that you have those files you want to go into matlab, change your directory to work in that same directory that you guys checked out from git. So we’re going to load this data. Ok, so, r is a 100 by 1 matrix, so let’s just plot r amd let’s see what it looks like. Alright, so, it has a bunch of random values that are between -5 and 5. So now let’s say I wanted to calculate the probability that r is equal to -5. How would I do that? So, one way is I could sum all the values where r is equal to -5 and divide it by the total number of values in r. So it gives me .07. I can do the same thing for every other value in the matrix. So we get about .06 to .11. So this is what we call the frequentist view of statistics. It means that if we flip a coin 1000 times, and that’s a fair coin with heads or tails, the probability is 50% and we should get heads about 500 times, and we should get tails about 500 times. The idea is that as the number of coin flips approaches infinity, our measurement of the probability of heads should approach 0.5. So we can also plot the histogram of r, and this should give us an idea of the shape of the distribution. Alright, so, let’s do a little more complex example. Let’s say I want to calculate the probability r is even. How can we do that? So in the same way as we did before, we might want to say r equals -4 or r equals -2, but that wouldn’t be the best way to do this. We would use the modulo function. So if mod(R,2) is equal to 0, that means r is even, divided by the length of r. Alright, so the probability that r is even is .43, and we can do the same thing to determine the probability that r is odd. And so notice that these two events are disjoint. You can either have r equals even or r equals odd, and those two events are the only possible events. So their probabilities should add up to 1, and we can verify that .43 plus .57 is equal to 1. Now so let’s say I want to test if r takes on a specific value, so let’s say I want to calculate the probability that r is equal to -5 or positive 5. How would I do that? So we would use the or operator. So r equals 5 or r equals -5, divided by the length of r. So the probability that r is equal to 5 or negative 5 is .21. Notice that we can use the same method for our first problem which was to determine even or odd. Which is the way I suggested not doing it, but we want to check our answers, and so that gives us the same answer. The probability that r is equal to -4, -2, 0, 2, or 4 is the same as the probability that r is even.
Subscribe on YouTube!
Most Popular Courses
-
The Complete Ethical Hacking Course Bundle!
Rated 4.62 out of 5
$780.00Original price was: $780.00.$19.99Current price is: $19.99. -
The Complete Linux Administration Course Bundle!
Rated 4.94 out of 5
$780.00Original price was: $780.00.$19.99Current price is: $19.99. -
26 Course Forever Bundle!
Rated 5.00 out of 5
$2,730.00Original price was: $2,730.00.$39.99Current price is: $39.99. -
The Complete MATLAB 7 Course Bundle!
Rated 4.60 out of 5
$585.00Original price was: $585.00.$29.99Current price is: $29.99. -
The Learn to Code 8 Course Bundle!
Rated 5.00 out of 5
$780.00Original price was: $780.00.$19.99Current price is: $19.99. -
The Complete Python 3 Course: Beginner to Advanced!
Rated 5.00 out of 5
$199.99Original price was: $199.99.$9.99Current price is: $9.99. -
The Ermin Kreponic Course Bundle!
Rated 4.54 out of 5
$1,755.00Original price was: $1,755.00.$39.99Current price is: $39.99. -
The Complete Digital Marketing Course Bundle!
$780.00Original price was: $780.00.$19.99Current price is: $19.99. -
Certified Ethical Hacker Boot Camp!
$195.00Original price was: $195.00.$9.99Current price is: $9.99. -
Linux System Administration for Beginners!
Rated 5.00 out of 5
$199.99Original price was: $199.99.$9.99Current price is: $9.99.