Boolean Algebra Lecture 7: Supporting Material Dr Kathryn Merrick Tuesday 24 th March, 2009
Overview Revision of numerical types and operators Introduction to the Boolean type and operators Boolean logic
Revision: Numerical Types integer floating point number Examples: >> num_motors = 2; >> speed = 5.6; …
Revision: Numerical Operators +addition – subtraction /division *multiplication ^power =assignment Examples: >> result = 2 + 3; >> num_legs = 4; >> my_var = 4^2; …
Another Puzzle… You have a goat a wolf and a cabbage with you and you need to cross a river in a small boat to get back home. If left alone together, the goat will eat the cabbage and the wolf will eat the goat. With room for only two in the boat, how do you get to the other side of the river? How do we express things like ‘the goat will eat the cabbage’ in a programming language?
Demo 1: Boolean Types in MATLAB
The Boolean Type Can have two values: true false In MATLAB these are equivalent to 1 and 0 respectively Can be combined using logical operators &, | and ~ Behaviour of logical operators can be represented in truth tables
Demo 2: Boolean Operators in MATLAB
Summary: Boolean Operators &logical AND |logical OR ~logical NOT <less than <=less than or equal to >greater than >=greater than or equal to ==equal to ~=not equal to
Summary After today’s lecture you should be able to: Identify numerical operators Identify Boolean operators Use Boolean logic to create and evaluate Boolean expressions