76
Logic and Excel AND NOT OR IF

Logic and Excel

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Logic and Excel

Logic and Excel

AND

NOT

OR

IF

Page 2: Logic and Excel

Announcements

• We are at the mid point in the semester• Mid semester feedback surveys • Next few weeks will target quantitative

approaches to data analysis, reduction, and decision-making

Page 3: Logic and Excel

Logic and Excel

AND

NOT

OR

IF

Page 4: Logic and Excel

Poll QuestionI know a lot about logic and its usage in Excel.

A. Strongly agreeB. AgreeC. Don’t agree or disagreeD. DisagreeE. Strongly disagree

Page 5: Logic and Excel

Overview

• Logic– IF, AND, NOT, OR– COUNTIF, SUMIF, AVERAGEIF

• Truth Tables

Page 6: Logic and Excel

Logic: IF

• Identify conditions and determine actions

• Example: IF it is hot, I will wear beach attire to school. Otherwise, I will wear business casual attire.

IF

Page 7: Logic and Excel

Logic: AND

• Identify all conditions being true

• Example: If it is sunny AND hot, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

AND

Page 8: Logic and Excel

Logic: NOT

• Identify conditions not being true

• Example: If it is NOT cold, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

NOT

Page 9: Logic and Excel

Logic: OR

• Identify any condition being true

• Example: If it is sunny OR hot, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

OR

Page 10: Logic and Excel

Excel formulas and functions

• Formulas: equation used [with operators] to calculate a value– Operators: +, -, /, *, ^, >, <, =, >=, <=, <>, &– e.g. =A1+A3

• Functions: preprogrammed shortcuts for calculating equations– e.g. =sum(A1:A3)

Page 11: Logic and Excel

Poll QuestionFunctions are preprogrammed shortcuts for calculating equations.

A. TrueB. False

Page 12: Logic and Excel

Poll QuestionFormulas are equations used with operators to calculate values.

A. TrueB. False

Page 13: Logic and Excel

Practice problems

• How do you use the following with logical statements?– IF– AND– NOT– OR

• What is the difference between functions and formulas?

• What operators are used in Excel?

Page 14: Logic and Excel

Excel: IF function

• =IF(condition,value if true,value if false)• =IF(A1>=80,“hot”,“cool”)

Page 15: Logic and Excel

Excel logic

• Identify conditions and determine actions

• Example: IF it is hot, I will wear beach attire to school. Otherwise, I will wear business casual attire.

Let’s assume hot is 80 degrees or more

Page 16: Logic and Excel

Excel logic

• Identify conditions and determine actions

• Example: IF it is hot, I will wear beach attire to school. Otherwise, I will wear business casual attire.

B4: =IF(B2>=80, “beach attire”, “business casual attire”)

Page 17: Logic and Excel

Excel logic

• Identify conditions and determine actions

• Example: IF it is hot, I will wear beach attire to school. Otherwise, I will wear business casual attire.

B4: =IF(B2>=80, “beach attire”, “business casual attire”)

Page 18: Logic and Excel

Excel logic

• Identify conditions and determine actions

• Example: IF it is hot, I will wear beach attire to school. Otherwise, I will wear business casual attire.

B4: =IF(B2>=80, “beach attire”, “business casual attire”)

Page 19: Logic and Excel

Excel logic

• NOTE: B2>=80 (Hot)

Let’s assume hot is 80 degrees or more

Page 20: Logic and Excel

Excel logic

• B2>=80 (Hot)• B2>79 (Hot)• B2<80 (Cold)• B2<=79 (Cold)

Let’s assume hot is 80 degrees or more

Page 21: Logic and Excel

Excel logic

• Identify conditions and determine actions

• Example: IF it is hot, I will wear beach attire to school. Otherwise, I will wear business casual attire.

Page 22: Logic and Excel

Logic: AND

• Identify all conditions being true

• Example: If it is sunny AND hot, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

B4: =IF(AND(B3=“Sunny”,B2>=80), “beach attire”, “business casual attire”)

Page 23: Logic and Excel

Logic: AND

• Identify all conditions being true

• Example: If it is sunny AND hot, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

B4: =IF(AND(B3=“Sunny”,B2>=80), “beach attire”, “business casual attire”)

Page 24: Logic and Excel

Logic: NOT

• Identify conditions not being true

• Example: If it is NOT cold, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

B4: =IF(NOT(B2<80), “beach attire”, “business casual attire”)

Page 25: Logic and Excel

Logic: NOT

• Identify conditions not being true

• Example: If it is NOT cold, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

B4: =IF(NOT(B2<80), “beach attire”, “business casual attire”)

Page 26: Logic and Excel

Logic: OR

• Identify any condition being true

• Example: If it is sunny OR hot, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

B4: =IF(OR(B3=“Sunny”,B2>=80), “beach attire”, “business casual attire”)

Page 27: Logic and Excel

Logic: OR

• Identify any condition being true

• Example: If it is sunny OR hot, I will wear beach attire to school. Otherwise, I will wear business casual attire to school.

B4: =IF(OR(B3=“Sunny”,B2>=80), “beach attire”, “business casual attire”)

Page 28: Logic and Excel

Poll QuestionIf I eat more than 2000 calories, I will work out more. If not, no additional action is needed.

What function(s) can you enter into B4? A. =IF(B2>2000, “Work out more”, “no action needed”)B. =IF(B2>=2000, “Work out more”, “no action needed”)C. =IF(B2<2000, “no action needed”, “Work out more”)D. =IF(B2<=1999, “no action needed”, “Work out more”)E. Not enough information

Page 29: Logic and Excel

Poll QuestionIf I eat more calories than I burn, I will work out more. If not, no action is needed.

What function(s) can you enter into B4? A. =IF(B3>=B2, “no action needed”, “Work out more”)B. =IF(B2>B3, “Work out more”, “no action needed”)C. =IF(B3>B2, “no action needed”, “Work out more”)D. A and BE. B and CF. A and C

Page 30: Logic and Excel

What constitutes no action/work out more

• If I eat more calories than I burn, I will work out more. If not, no action is needed. – Calories eaten > calories burned [WO]– Calories eaten <= calories burned [NA]

WO=work outNA=no action

Page 31: Logic and Excel

What constitutes no action/work out more

• If I eat more calories than I burn, I will work out more. If not, no action is needed. – calories eaten > calories burned [WO]– calories burned < calories eaten [WO]– calories eaten <= calories burned [NA]– calories burned >= calories eaten [NA]

WO=work outNA=no action

Page 32: Logic and Excel

v

• If I eat more calories than I burn, I will work out more. If not, no action is needed.

A. B3>=B2 : calories burned >= calories eaten [NA]B. B2>B3 : calories eaten >calories burned [WO]C. B3>B2 : calories burned > calories eaten [NA]

Page 33: Logic and Excel

v

• If I eat more calories than I burn, I will work out more. If not, no action is needed.

A. B3>=B2 : calories burned >= calories eaten [NA]B. B2>B3 : calories eaten >calories burned [WO]C. B3>B2 : calories burned > calories eaten [NA]

calories eaten > calories burned [WO]calories burned < calories eaten [WO]calories eaten <= calories burned [NA]calories burned >= calories eaten [NA]

Page 34: Logic and Excel

• If I eat more calories than I burn, I will work out more. If not, no action is needed.

A. B3>=B2 : calories burned >= calories eaten [NA]B. B2>B3 : calories eaten >calories burned [WO]C. B3>B2 : calories burned > calories eaten [NA]

calories eaten > calories burned [WO]calories burned < calories eaten [WO]calories eaten <= calories burned [NA]calories burned >= calories eaten [NA]

Page 35: Logic and Excel

Poll QuestionIf I eat less than 2000 calories and burn more than 2000 calories, I will eat more. If not, no additional action is needed.

What function should you enter into B4? A. =IF(AND(B2>2000, B3<2000), “eat more”, “no additional action needed”)B. =IF(AND(B2<2000, B3>2000), “eat more”, “no additional action needed”)C. =IF(AND(B2<=2000, B3>=2000), “eat more”, “no additional action

needed”)D. =IF(NOT(B2<2000, B3>2000), “eat more”, “no additional action needed”)E. Cannot determine from information given

Page 36: Logic and Excel

Embedded IF

Page 37: Logic and Excel

Embedded IF

• Grades– A: 900 or higher– B: 800 to 899– C: 700 to 799– D: 600 to 699– F: 0-599

Page 38: Logic and Excel

Embedded IF

=IF(H2>=900,"A",IF(H2>=800,"B",IF(H2>=700,"C",IF(H2>=600,"D","F"))))

Page 39: Logic and Excel

Embedded IF

Page 40: Logic and Excel

Embedded IF

Or, we can use lookup functions to calculate grades.

Page 41: Logic and Excel

Other IF functions

• SUMIF: sum a range if criteria is met• COUNTIF: count a range if criteria is met• AVERAGEIF: average of a range if criteria is

met

Page 42: Logic and Excel

AVERAGEIF

Page 43: Logic and Excel

AVERAGEIF

Cell C13: =AVERAGEIF(B2:B11,"Teacher A",I2:I11)

Page 44: Logic and Excel

AVERAGEIF

Cell C13: =AVERAGEIF(B2:B11,"Teacher A",I2:I11)

What is the function in cell C14?

Page 45: Logic and Excel

Poll QuestionWhat is the function used in cell C14 to calculate average total score for teacher B?

A. =AVERAGEIF(I2:I11,"Teacher B", B2:B11) B. =IFAVERAGE(AVERAGEIF(I2:I11,"Teacher B", B2:B11) C. =AVERAGEIF(A2:A11,"Teacher B",I2:I11) D. =IFAVERAGE(B2:B11,"Teacher B",I2:I11)E. =AVERAGEIF(B2:B11,"Teacher B",I2:I11)

Page 46: Logic and Excel

COUNTIF

Page 47: Logic and Excel

COUNTIF

C16: =COUNTIF(J2:J11,"A")

Page 48: Logic and Excel

Poll QuestionIf I used the COUNTIF function to count grades in ICS 101 (A+ to F), how many possible grades exist?

A. 1B. 4C. 5D. 13E. 15

Page 49: Logic and Excel

Practice problems• How do the IF, AND, NOT, and OR functions work in Excel?

– What could you use these functions for in your checklist?– Hint: Do any of these functions help you to make a decision?– Example: Return rates and reverse logistics

• Use an embedded IF statement to calculate grades for ICS 101. Check the syllabus for the grade breakdown.– Hint: The embedded IF statement will be longer than the

example in this lecture due to the +/- scale.• What is the arguments list for SUMIF if it uses the same

arguments list as the COUNTIF and AVERAGEIF functions?• How do the COUNTIF, and AVERAGEIF functions work?

– What could you use these functions for in your checklist?– Hint: When do you want to search and conduct one of these

analyses?

Page 50: Logic and Excel
Page 51: Logic and Excel

XOR: Exclusive OR(Cats OR Dogs) AND NOT (Cats AND Dogs)

Page 52: Logic and Excel

Logic Symbols

Expression Meaning¬ x not x

x ∧ y x and yx ∨ y x or y

Page 53: Logic and Excel

Compound Logic

x ¬ x

FALSE TRUE

TRUE FALSE

x y x ∧ y

FALSE FALSE FALSE

FALSE TRUE FALSE

TRUE FALSE FALSE

TRUE TRUE TRUE

x y x ∨ y

FALSE FALSE FALSE

FALSE TRUE TRUE

TRUE FALSE TRUE

TRUE TRUE TRUE

Page 54: Logic and Excel

Truth TablesA quick way to understand the nature of a function, or to see if

two functions are equivalent (have the same truth values). Show every possible combination of the variables. Here is a truth table for XOR (the exclusive OR)*:

(x ∨ y) ∧ ¬ (x ∧ y)

Page 55: Logic and Excel

Truth TablesA quick way to understand the nature of a function, or to see if

two functions are equivalent (have the same truth values). Show every possible combination of the variables. Here is a truth table for XOR (the exclusive OR)*:

x y (x ∨ y) (x ∧ y) ¬ (x ∧ y) (x ∨ y) ∧ ¬ (x ∧ y)

FALSE FALSE

FALSE TRUE

TRUE FALSE

TRUE TRUE

(x ∨ y) ∧ ¬ (x ∧ y)

Page 56: Logic and Excel

Truth TablesA quick way to understand the nature of a function, or to see if

two functions are equivalent (have the same truth values). Show every possible combination of the variables. Here is a truth table for XOR (the exclusive OR)*:

x y (x ∨ y) (x ∧ y) ¬ (x ∧ y) (x ∨ y) ∧ ¬ (x ∧ y)

FALSE FALSE FALSE

FALSE TRUE TRUE

TRUE FALSE TRUE

TRUE TRUE TRUE

(x ∨ y) ∧ ¬ (x ∧ y)

Page 57: Logic and Excel

Truth TablesA quick way to understand the nature of a function, or to see if

two functions are equivalent (have the same truth values). Show every possible combination of the variables. Here is a truth table for XOR (the exclusive OR)*:

x y (x ∨ y) (x ∧ y) ¬ (x ∧ y) (x ∨ y) ∧ ¬ (x ∧ y)

FALSE FALSE FALSE FALSE

FALSE TRUE TRUE FALSE

TRUE FALSE TRUE FALSE

TRUE TRUE TRUE TRUE

(x ∨ y) ∧ ¬ (x ∧ y)

Page 58: Logic and Excel

Truth TablesA quick way to understand the nature of a function, or to see if

two functions are equivalent (have the same truth values). Show every possible combination of the variables. Here is a truth table for XOR (the exclusive OR)*:

x y (x ∨ y) (x ∧ y) ¬ (x ∧ y) (x ∨ y) ∧ ¬ (x ∧ y)

FALSE FALSE FALSE FALSE TRUE

FALSE TRUE TRUE FALSE TRUE

TRUE FALSE TRUE FALSE TRUE

TRUE TRUE TRUE TRUE FALSE

(x ∨ y) ∧ ¬ (x ∧ y)

Page 59: Logic and Excel

Truth TablesA quick way to understand the nature of a function, or to see if

two functions are equivalent (have the same truth values). Show every possible combination of the variables. Here is a truth table for XOR (the exclusive OR)*:

x y (x ∨ y) (x ∧ y) ¬ (x ∧ y) (x ∨ y) ∧ ¬ (x ∧ y)

FALSE FALSE FALSE FALSE TRUE FALSE

FALSE TRUE TRUE FALSE TRUE TRUE

TRUE FALSE TRUE FALSE TRUE TRUE

TRUE TRUE TRUE TRUE FALSE FALSE

(x ∨ y) ∧ ¬ (x ∧ y)

Page 60: Logic and Excel

Live Practice

On a sheet of paper or on your computing device, draw a truth table for:

(x ∨ y) ∧ (¬ x ∨ ¬ y)

Page 61: Logic and Excel

In-class practice

Draw a truth table for:

(x ∨ y) ∧ (¬ x ∨ ¬ y)

x y (x ∨ y) ¬ x ¬ y (¬x ∨ ¬y) (x ∨ y) ∧ (¬ x ∨ ¬ y)

FALSE FALSE

FALSE TRUE

TRUE FALSE

TRUE TRUE

Page 62: Logic and Excel

Truth Tables

(x ∨ y) ∧ (¬ x ∨ ¬ y)

x y (x ∨ y) ¬ x ¬ y (¬x ∨ ¬y) (x ∨ y) ∧ (¬ x ∨ ¬ y)

FALSE FALSE FALSE TRUE TRUE TRUE FALSE

FALSE TRUE TRUE TRUE FALSE TRUE TRUE

TRUE FALSE TRUE FALSE TRUE TRUE TRUE

TRUE TRUE TRUE FALSE FALSE FALSE FALSE

Page 63: Logic and Excel

x y (x ∨ y) (x ∧ y) ¬ (x ∧ y) (x ∨ y) ∧ ¬ (x ∧ y)

FALSE FALSE FALSE FALSE TRUE FALSE

FALSE TRUE TRUE FALSE TRUE TRUE

TRUE FALSE TRUE FALSE TRUE TRUE

TRUE TRUE TRUE TRUE FALSE FALSE

(x ∨ y) ∧ (¬ x ∨ ¬ y)

(x ∨ y) ∧ ¬ (x ∧ y)

x y (x ∨ y) ¬ x ¬ y (¬x ∨ ¬y) (x ∨ y) ∧ (¬ x ∨ ¬ y)

FALSE FALSE FALSE TRUE TRUE TRUE FALSE

FALSE TRUE TRUE TRUE FALSE TRUE TRUE

TRUE FALSE TRUE FALSE TRUE TRUE TRUE

TRUE TRUE TRUE FALSE FALSE FALSE FALSE

Page 64: Logic and Excel

XOR: Exclusive OR(Cats OR Dogs) AND NOT (Cats AND Dogs) = (x ∨ y) ∧ ¬ (x ∧ y)

(Cats OR Dogs) AND (NOT Cats OR NOT Dogs) = (x ∨ y) ∧ (¬ x ∨ ¬ y)

Page 65: Logic and Excel

Cats OR Dogs ≠ (Cats OR Dogs) AND NOT (Cats AND Dogs)

Page 66: Logic and Excel

Hamilton Library Ground Floor, Courtesy of Sean Mosier

Page 67: Logic and Excel

Poll QuestionI find this sign to be ominous.

A. Strongly agreeB. AgreeC. Don’t agree or disagreeD. DisagreeE. Strongly disagree

Page 68: Logic and Excel

(Read OR Die) AND NOT (Read AND Die)

Page 69: Logic and Excel

Read OR Die

Page 70: Logic and Excel

Practice problems

• Given a logical statement can you create a truth table?

• Can you think of other logical statements that could be the equivalent of the exclusive or (XOR)?– Test it by creating a truth table

Page 71: Logic and Excel

On-line lecture

• Review logic and truth tables• Apply logic and truth tables to Excel• Practice using Excel.

Page 72: Logic and Excel

Reminders

• Reminders: – Plagiarism tutorial 2 will open soon

Page 73: Logic and Excel

It is the middle of the semester. Would you like a midterm surprise?

Page 74: Logic and Excel

We normally have the midterm exam around this time of the semester.

Page 75: Logic and Excel

Since we have an extra week of lecture, my teaching team and I decided to makethis week’s lecture quiz EXTRA CREDIT. The content is still required for the course, but the points you earn will be EC.

Page 76: Logic and Excel

Poll QuestionI learned a lot about logic and its usage in Excel.

A. Strongly agreeB. AgreeC. Don’t agree or disagreeD. DisagreeE. Strongly disagree