To Calculate Probabilities in MATLAB, The Number of Points Within Each Boundary Must Be Indexed in The Following Way (1 Represents A Hit, So The Point Is Within The Boundary)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

2)c)ii)

To calculate probabilities in MATLAB, the number of points within each boundary must be indexed
in the following way (1 represents a hit, so the point is within the boundary):

>> A = 2430 < density & density < 2450 >> B = 55 < strength & strength < 65 >> Atotal = 2410 < density & density < 2489 >> Btotal = 48 < strength & strength < 71
A= B= Atotal = Btotal =

1 1 1 1
1 1 1 1
0 1 1 1
0 0 1 1
0 1 1 1
1 0 1 1
0 0 1 1
1 0 1 1
1 1 1 1
1 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
1 1 1 1
1 1 1 1
0 0 1 1
1 0 1 1
0 0 1 1
0 1 1 1
1 1 1 1
1 1 1 1
0 1 1 1
0 1 1 1
1 1 1 1
1 1 1 1
0 1 1 1
1 1 1 1
1 0 1 1
0 1 1 1
0 0 1 1
1 1 1 1
1 1 1 1
1 0 1 1
0 0 1 1
0 1 1 1
0 1 1 1
0 0 1 1
0 1 1 1
0 0 1 1
0 1 1 1

Also as P(AandB) will need to be found, the following boundary, which includes both the
density and strength, must be defined: >> AandB = A & B
This simply indexes the points which fit both criteria, A and B.
Then, these indexed “hits” must be counted, which involves a simple sum of all the 1’s
above.
>> sum(Atotal)

ans =

40

>> sum(Btotal)

ans =

40

>> sum(A)

ans =

20

>> sum(B)

ans =

26

>> sum(AandB)

ans =

15

=================================================================================================================
====

Then, the probabilities are found simply by inputting the different formulae, using the
basic
>> ProbA = sum(A)/sum(Atotal)
ProbA =

0.5000
>> ProbB = sum(B)/sum(Btotal)
ProbB =

0.6500
In this case, ProbAandB had to be done slightly differently, as it involved boundaries
within two variables.
>> >> ProbAandB = sum(AandB)/sum(Atotal)
ProbAandB =

0.3750
Then, we can use this to find P(A|B)
>> ProbAgivenB = ProbAandB/ProbB
ProbAgivenB =

0.5769

You might also like