<< Chapter < Page Chapter >> Page >

Then

E F [ 1 1 0 0 1 1 1 1 ] , E F [ 0 1 0 0 0 0 0 1 ] , and E c [ 1 0 1 1 0 1 0 0 ]

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 E , F of the same size

  • E | F is the matrix obtained by taking the maximum element in each place.
  • E & F is the matrix obtained by taking the minimum element in each place.
  • E C is the matrix obtained by interchanging one and zero in each place in E .

Thus, if E , F are minterm vectors for sets by the same name, then E | F is the minterm vector for E F , E & F is the minterm vector for E F , and E = 1 - E is the minterm vector for E c .

This suggests a general approach to determining minterm vectors for Boolean combinations.

  1. Start with minterm vectors for the generating sets.
  2. Use MATLAB logical operations to obtain the minterm vector for any Boolean combination.

Suppose, for example, the class of generating sets is { A , B , C } . Then the minterm vectors for A , B , and C , respectively, are

A = [ 0 0 0 0 1 1 1 1 ] B = [ 0 0 1 1 0 0 1 1 ] C = [ 0 1 0 1 0 1 0 1 ]

If E = A B C c , then the logical combination E = ( A & B ) | C of the matrices yields E = [ 1 0 1 0 1 0 1 1 ] .

MATLAB implementation

A key step in the procedure just outlined is to obtain the minterm vectors for the generating elements { A , B , C } . 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.

Minterms for the class { A , B , C } .

>>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
Got questions? Get instant answers now!

Minterm patterns for the boolean combinations

F = A B B c C G = A A c C

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)
Got questions? Get instant answers now!

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.

  1. A numerical matrix (or vector) subject to the usual operations on matrices..
  2. A logical array whose elements are combined by a. Logical operators to give new logical arrays;b. Array operations (element by element) to give numerical matrices; c. Array operations with numerical matrices to give numerical results.

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.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Applied probability. OpenStax CNX. Aug 31, 2009 Download for free at http://cnx.org/content/col10708/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Applied probability' conversation and receive update notifications?

Ask