Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Similar presentations


Presentation on theme: "Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display."— Presentation transcript:

1 Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

2 Learning Excel Excel is learned by working in Excel Lab 1 (and a future graphics lab) will have Excel problems Assignment 1 will be an Excel problem Textbook Chapter 2 covers Excel Many online tutorials

3 Excel Exam Subjects There are two topics in Chapter 2 that may be on written exams: IF statements (including AND, OR logic) Linear interpolation

4 The IF Statement Logical (decision) statements are used to control the sequence of computations in programs and in spreadsheet MATLAB and Excel both contain IF statements for adding logical control An IF statement tests a condition, and the flow of calculations is dependent on whether the condition is true or false This is best illustrated with a simple example

5 Logical Test Example Consider taking the absolute value of a number How would you instruct Excel to perform this function (without using the built-in function ABS) There are ways to accomplish this without an IF statement (for example, you can square the number and then take its square root, which always returns the positive root), but the most straightforward method is to use a logical test Engineering Computation: An Introduction Using MATLAB and Excel

6 Logical Test Example (cont.) In words, you might describe your procedure as: “If the number is less then zero, then take the negative of that number, else leave the number as it is” This if-then-else logic is widely used in programming, and can also be used in Excel Format of Excel IF statement: -if(logical_test,value_if_true,value_if_false) Engineering Computation: An Introduction Using MATLAB and Excel

7 Excel IF Statement The IF statement is a function, with three arguments The first argument is the logical test (the condition). For our example, the logical test will be that the value of the number considered is less than zero The second argument is the action to be taken if the condition is true (take the negative of the number) The third argument is the action to be taken if the condition is false (report the input number unchanged) Engineering Computation: An Introduction Using MATLAB and Excel

8 Absolute Value Example The number to be evaluated is entered into cell A1 The formula is entered into cell B1 Engineering Computation: An Introduction Using MATLAB and Excel

9 Nesting IF Statements Often, there will be more than two possible outputs for a given input In MATLAB, we use the if-then-else function In Excel, we must nest IF statements Consider this example: we want to read in a numerical grade and convert it to a letter grade on a scale of: – Greater than or equal to 90 = A, – Greater than or equal to 80 and less than 90 = B – Greater than or equal to 70 and less than 80 = C – Greater than or equal to 60 and less than 70 = D – Less than or equal to 60 = F Engineering Computation: An Introduction Using MATLAB and Excel

10 Excel Formula Engineering Computation: An Introduction Using MATLAB and Excel Consider this first IF statement: If true, “A” is entered into cell B1 If false, then another IF statement is encountered Note the use of “>=” for greater than or equal to: If just “>” (greater than) is used, then a grade of exactly 90 would be a B.

11 Examples Engineering Computation: An Introduction Using MATLAB and Excel

12 Alternate Solution Engineering Computation: An Introduction Using MATLAB and Excel

13 Alternate Solution #2 Engineering Computation: An Introduction Using MATLAB and Excel First Logical Test Value if False Value if True (leads to further tests) Pay close attention to parentheses!

14 Combining Conditions The AND and OR statements can be used for multiple conditions Formats: AND(condition1, condition2…) True only if all conditions are true OR(condition1, condition2…) True if any one of the conditions is true Engineering Computation: An Introduction Using MATLAB and Excel

15 Example In a manufacturing operation, a part must have a measured length between 1.99 and 2.02 inches, or it is rejected Excel formula: The condition for the IF statement is true only if both conditions following the AND statement are true: To be accepted, the part must be greater than the minimum allowed AND less than the maximum allowed. Engineering Computation: An Introduction Using MATLAB and Excel

16 Example Alternate solution: The condition for the IF statement is true only if either of the conditions following the OR statement is true: To be rejected, the part length must be less than the minimum allowed OR greater than the maximum allowed. Engineering Computation: An Introduction Using MATLAB and Excel

17 Example Both solutions give the same results Could also have used nested IF statements rather than AND/OR for this example Engineering Computation: An Introduction Using MATLAB and Excel


Download ppt "Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display."

Similar presentations


Ads by Google