Lecture 14

# Lecture 14 - 14:440:127 Introduction to Computers for...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 14:440:127 Introduction to Computers for Engineers Notes for Lecture 14- Final Exam OMG! Rutgers University, Fall 2009 Instructor- Blase E. Ur 1 Basics Key Idea 0: The names of m-files and of variables must start with a letter, and can only contain letters, numbers, and the underscore... AND NO SPACES ARE ALLOWED!!!! Key Idea 1: The relational operators are > , >= , < , <= , == , ~= . Notice that those last two operators signify is it equal to and is it UNequal to, respectively. Each of these operators returns either 0 (false) or 1 (true). Key Idea 2: 0 is false. 1 and all other non-zero values are true. Key Idea 3: To connect two or more statements, each of which is true or false, use the logical operators: & (AND) is true only if the statement before it AND the statement after it are both true. | (OR) is true if either the statement before it OR the statement after it is true. ~ (NOT) reverses true and false. ~1 is false, whereas ~0 is true. 2 Conditionals 2.1 If Key Idea 1: An If Statement begins with if(condition) , where the condition evaluates to true or false. If the condition is true, Matlab executes the statements following the if and preceding end . If the condition is not true, Matlab skips those statements. Key Idea 2: If the first condition is not true, you can follow with an else statement. You cant write any condition after else . If the original condition is false, Matlab executes the statements following else . Key Idea 3: If you want to have a bunch of possible courses of action, you can have elseif statements. First, youll have an if condition, then 0 or more elseif conditions, and then you might (or might not) have an else . Going down the list of conditions, Matlab executes the statements following the first condition that is true, and it skips the rest . There is only a single end , all the way at the bottom. 2.2 Switch Key Idea 1: Instead of using if statements, if you have a single variable that takes on a small number of discrete values, you can use switch case . i.e. Menus are excellent times to use switch. Key Idea 2: Start off by typing switch VARIABLEname . Key Idea 3: Then, for each value, type case VALUE i.e case 5 . Dont put something like case x==5 , youve already specified the variable in the switch statement. That would give you an error. 1 Key Idea 4: An if statement uses else to capture all other possibilities. A switch statement uses otherwise . Key Idea 5: To test a couple of possible values in a single case, surround those values by squigly braces, i.e. case {5,6,7} will test if the variable is 5, 6, or 7. x = menu(What do you think about Soulja Boy?, He sucks, He really sucks.); switch x case 1 disp(Correct.) case 2 disp(More correct.) otherwise disp(This will never actually display) end 3 Built-In Math Functions Matlab includes many built-in functions for math operations. Here are a number of the most importantMatlab includes many built-in functions for math operations....
View Full Document

## This note was uploaded on 01/11/2010 for the course 440 127 taught by Professor Blase during the Fall '09 term at Rutgers.

### Page1 / 10

Lecture 14 - 14:440:127 Introduction to Computers for...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online