15.11.2014 Views

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

278 <strong>Chapter</strong> 4 <strong>Programm<strong>in</strong>g</strong> <strong>in</strong> <strong>Matlab</strong><br />

A B A & B<br />

1 1 1<br />

1 0 0<br />

0 1 0<br />

0 0 0<br />

A B A | B<br />

1 1 1<br />

1 0 1<br />

0 1 1<br />

0 0 0<br />

A<br />

∼ A<br />

1 0<br />

0 1<br />

(a) AND (b) OR (c) NOT<br />

Table 4.2.<br />

Truth tables for <strong>Matlab</strong>’s logical operators.<br />

The first and third entries <strong>of</strong> vectors u and v are logical 1’s (true), hence <strong>the</strong><br />

first and third entries <strong>of</strong> u&v will be logical 1’s (true). Accord<strong>in</strong>g to Table 4.2(a),<br />

all o<strong>the</strong>r entries <strong>of</strong> u&v will be logical 0’s (false).<br />

>> u, v, u&v<br />

u =<br />

1 1 1 0 0<br />

v =<br />

1 0 1 0 1<br />

ans =<br />

1 0 1 0 0<br />

On <strong>the</strong> o<strong>the</strong>r hand, Table 4.2(b) <strong>in</strong>dicates that u|v (OR) will be false if and<br />

only if both entries are false. In <strong>the</strong> case <strong>of</strong> <strong>the</strong> vectors u and v, <strong>the</strong> fourth entry<br />

<strong>of</strong> each vector is logical 0 (false), so <strong>the</strong> fourth entry <strong>of</strong> u|v will be logical 0 (false).<br />

All o<strong>the</strong>r entries <strong>of</strong> u|v will be logical 1’s (true).<br />

>> u, v, u|v<br />

u =<br />

1 1 1 0 0<br />

v =<br />

1 0 1 0 1<br />

ans =<br />

1 1 1 0 1<br />

u.<br />

F<strong>in</strong>ally, ~u simply reverses <strong>the</strong> truth or falsehood <strong>of</strong> each entry <strong>of</strong> <strong>the</strong> vector

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!