<< Chapter < Page | Chapter >> Page > |
Then
MATLAB logical operations
MATLAB logical operations on zero-one matrices provide a convenient way of handling Boolean combinations of minterm vectors represented as matrices. For two zero-one matrices of the same size
Thus, if are minterm vectors for sets by the same name, then is the minterm vector for , is the minterm vector for , and is the minterm vector for E c .
This suggests a general approach to determining minterm vectors for Boolean combinations.
Suppose, for example, the class of generating sets is . Then the minterm vectors for , and C , respectively, are
If , then the logical combination of the matrices yields .
MATLAB implementation
A key step in the procedure just outlined is to obtain the minterm vectors for the generating
elements
. We have an m-function to provide
such fundamental vectors. For example to produce the second minterm vector for the family(i.e., the minterm vector for
B ), the basic zero-one pattern
0 0 1 1
is replicated
twice to give
0 0 1 1 0 0 1 1
The function minterm(n,k) generates the k th minterm vector for a class of n generating sets.
>>A = minterm(3,1)
A = 0 0 0 0 1 1 1 1>>B = minterm(3,2)
B = 0 0 1 1 0 0 1 1>>C = minterm(3,3)
C = 0 1 0 1 0 1 0 1
F = (A&B)|(~B&C)
F = 0 1 0 0 0 1 1 1>>G = A|(~A&C)
G = 0 1 0 1 1 1 1 1>>JF = find(F)-1 % Use of find to determine index set for F
JF = 1 5 6 7 % Shows F = M(1, 5, 6, 7)
These basic minterm patterns are useful not only for Boolean combinations of events but also for many aspects of the analysis of those random variables which take on onlya finite number of values.
Zero-one arrays in MATLAB
The treatment above hides the fact that a rectangular array of zeros and ones can have two quite different meanings and functions in MATLAB.
Some simple examples will illustrate the principal properties.
>>>A = minterm(3,1);>>B = minterm(3,2);>>C = minterm(3,3);>>F = (A&B)|(~B&C)
F = 0 1 0 0 0 1 1 1>>G = A|(~A&C)
G = 0 1 0 1 1 1 1 1>>islogical(A) % Test for logical array
ans = 0>>islogical(F)
ans = 1>>m = max(A,B) % A matrix operation
m = 0 0 1 1 1 1 1 1>>islogical(m)
ans = 0>>m1 = A|B % A logical operation
m1 = 0 0 1 1 1 1 1 1>>islogical(m1)
ans = 1>>a = logical(A) % Converts 0-1 matrix into logical array
a = 0 0 0 0 1 1 1 1>>b = logical(B)>>m2 = a|b
m2 = 0 0 1 1 1 1 1 1>>p = dot(A,B) % Equivalently, p = A*B'
p = 2>>p1 = total(A.*b)p1 = 2>>p3 = total(A.*B)
p3 = 2>>p4 = a*b' % Cannot use matrix operations on logical arrays
??? Error using ==>mtimes % MATLAB error signal
Logical inputs must be scalar.
Notification Switch
Would you like to follow the 'Applied probability' conversation and receive update notifications?