Boolean algebra, conditional statements, loops.
|
|
- Shavonne Anderson
- 6 years ago
- Views:
Transcription
1 Boolean algebra, conditional statements, loops. Eugeniy E. Mikhailov The College of William & Mary Lecture 04 Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 1 / 19
2 Boolean algebra Variable of valuable type can have only two values true false Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 2 / 19
3 Boolean algebra Variable of valuable type can have only two values true (Matlab use 1 to indicate it, actually everything but zero) false Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 2 / 19
4 Boolean algebra Variable of valuable type can have only two values true (Matlab use 1 to indicate it, actually everything but zero) false (Matlab uses 0 ) Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 2 / 19
5 Boolean algebra Variable of valuable type can have only two values true (Matlab use 1 to indicate it, actually everything but zero) false (Matlab uses 0 ) There are three logical operators which are used in boolean algebra Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 2 / 19
6 Boolean algebra Variable of valuable type can have only two values true (Matlab use 1 to indicate it, actually everything but zero) false (Matlab uses 0 ) There are three logical operators which are used in boolean algebra - logic not, Matlab true = false false = true Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 2 / 19
7 Boolean algebra Variable of valuable type can have only two values true (Matlab use 1 to indicate it, actually everything but zero) false (Matlab uses 0 ) There are three logical operators which are used in boolean algebra - logic not, Matlab true = false false = true - logic and, Matlab & { true, if A=true and B=true, A B = false, otherwise Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 2 / 19
8 Boolean algebra Variable of valuable type can have only two values true (Matlab use 1 to indicate it, actually everything but zero) false (Matlab uses 0 ) There are three logical operators which are used in boolean algebra - logic not, Matlab true = false false = true - logic and, Matlab & { true, if A=true and B=true, A B = false, otherwise - logic or, Matlab { false, if A=false and B=false, A B = true, otherwise Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 2 / 19
9 Boolean operators precedence in Matlab If A = false, B = true, C = true A B&C Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 3 / 19
10 Boolean operators precedence in Matlab If A = false, B = true, C = true A B&C has highest precedence, then &, and then Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 3 / 19
11 Boolean operators precedence in Matlab If A = false, B = true, C = true A B&C has highest precedence, then &, and then A (( B)&C) Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 3 / 19
12 Boolean operators precedence in Matlab If A = false, B = true, C = true A B&C has highest precedence, then &, and then A (( B)&C) Thus A B&C = false Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 3 / 19
13 Boolean operators precedence in Matlab If A = false, B = true, C = true A B&C has highest precedence, then &, and then A (( B)&C) Thus A B&C = false Cat is an animal and cat is not an animal Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 3 / 19
14 Boolean operators precedence in Matlab If A = false, B = true, C = true A B&C has highest precedence, then &, and then Thus A (( B)&C) A B&C = false Cat is an animal and cat is not an animal is false statement Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 3 / 19
15 Boolean operators precedence in Matlab If A = false, B = true, C = true A B&C has highest precedence, then &, and then Thus A (( B)&C) A B&C = false Cat is an animal and cat is not an animal is false statement Z &Z = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 3 / 19
16 Boolean operators precedence in Matlab If A = false, B = true, C = true A B&C has highest precedence, then &, and then Thus A (( B)&C) A B&C = false Cat is an animal and cat is not an animal is false statement Z &Z = false Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 3 / 19
17 Boolean logic examples There is an island, which is populated by two kind of people: liars and truthlovers. Liars always lie and never speak a word of truth. Truthlovers always speak only truth. Suppose, you are landed on this island and met a person. What will be the answer to your question Who are you? Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 4 / 19
18 Boolean logic examples There is an island, which is populated by two kind of people: liars and truthlovers. Liars always lie and never speak a word of truth. Truthlovers always speak only truth. Suppose, you are landed on this island and met a person. What will be the answer to your question Who are you? The answer always will be Truthlover. Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 4 / 19
19 Boolean logic examples There is an island, which is populated by two kind of people: liars and truthlovers. Liars always lie and never speak a word of truth. Truthlovers always speak only truth. Suppose, you are landed on this island and met a person. What will be the answer to your question Who are you? The answer always will be Truthlover. Now you see a person who answers to your question. I am a liar. Is it possible? Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 4 / 19
20 Boolean logic examples There is an island, which is populated by two kind of people: liars and truthlovers. Liars always lie and never speak a word of truth. Truthlovers always speak only truth. Suppose, you are landed on this island and met a person. What will be the answer to your question Who are you? The answer always will be Truthlover. Now you see a person who answers to your question. I am a liar. Is it possible? This makes a paradox and should not ever happen on this island. Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 4 / 19
21 Matlab boolean logic examples & 12= Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 5 / 19
22 Matlab boolean logic examples & 12= e-6 = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 5 / 19
23 Matlab boolean logic examples & 12= e-6 = 0 Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 5 / 19
24 Matlab boolean logic examples & 12= e-6 = 0 >> B=[ , 0; , 12] B = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 5 / 19
25 Matlab boolean logic examples & 12= e-6 = 0 >> B=[ , 0; , 12] B = ~B Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 5 / 19
26 Matlab boolean logic examples & 12= e-6 = 0 >> B=[ , 0; , 12] B = ~B ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 5 / 19
27 Matlab boolean logic examples & 12= e-6 = 0 >> B=[ , 0; , 12] B = ~B ans = B ~B Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 5 / 19
28 Matlab boolean logic examples & 12= e-6 = 0 >> B=[ , 0; , 12] B = ~B ans = B ~B To be or not to be ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 5 / 19
29 Matlab boolean logic examples >> B=[ , 0; , 12] B = >> A=[56, 655; 0, 24.4] A = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 6 / 19
30 Matlab boolean logic examples >> B=[ , 0; , 12] B = >> A=[56, 655; 0, 24.4] A = B&A Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 6 / 19
31 Matlab boolean logic examples >> B=[ , 0; , 12] B = >> A=[56, 655; 0, 24.4] A = B&A ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 6 / 19
32 Matlab boolean logic examples >> B=[ , 0; , 12] B = >> A=[56, 655; 0, 24.4] A = B&A A ~B ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 6 / 19
33 Matlab boolean logic examples >> B=[ , 0; , 12] B = >> A=[56, 655; 0, 24.4] A = B&A ans = A ~B ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 6 / 19
34 Comparison operators Math Matlab = == double equal sign! = < < <= > > >= Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 7 / 19
35 Comparison operators Math x=[1,2,3,4,5] x = Matlab = == double equal sign! = < < <= > > >= Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 7 / 19
36 Comparison operators Math x=[1,2,3,4,5] x = x >= 3 Matlab = == double equal sign! = < < <= > > >= Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 7 / 19
37 Comparison operators Math x=[1,2,3,4,5] x = x >= 3 ans = Matlab = == double equal sign! = < < <= > > >= Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 7 / 19
38 Comparison operators Math x=[1,2,3,4,5] x = Matlab = == double equal sign! = < < <= > > >= x >= 3 ans = % chose such x where x>=3 x(x >= 3) Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 7 / 19
39 Comparison operators Math x=[1,2,3,4,5] x = Matlab = == double equal sign! = < < <= > > >= x >= 3 ans = % chose such x where x>=3 x(x >= 3) ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 7 / 19
40 Comparison with matrices >> A=[1,2;3,4] A = >> B=[33,11;53,42] B = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 8 / 19
41 Comparison with matrices >> A=[1,2;3,4] A = >> B=[33,11;53,42] B = A>=2 Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 8 / 19
42 Comparison with matrices >> A=[1,2;3,4] A = >> B=[33,11;53,42] B = A>=2 ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 8 / 19
43 Comparison with matrices >> A=[1,2;3,4] A = >> B=[33,11;53,42] B = A>=2 A(A>=2) ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 8 / 19
44 Comparison with matrices >> A=[1,2;3,4] A = >> B=[33,11;53,42] B = A>=2 ans = A(A>=2) ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 8 / 19
45 Comparison with matrices >> A=[1,2;3,4] A = >> B=[33,11;53,42] B = A>=2 ans = A(A>=2) ans = B(A>=2) Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 8 / 19
46 Comparison with matrices >> A=[1,2;3,4] A = >> B=[33,11;53,42] B = A>=2 ans = A(A>=2) ans = B(A>=2) ans = Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 8 / 19
47 if-else- statement if expression this part is executed only if expression is true else this part is executed only if expression is false Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 9 / 19
48 if-else- statement if expression this part is executed only if expression is true else this part is executed only if expression is false if hungry buy some food else keep working Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 9 / 19
49 if-else- statement if expression this part is executed only if expression is true else this part is executed only if expression is false if hungry buy some food else keep working if (x>=0) y=sqrt(x); else error( cannot do ); Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 9 / 19
50 Common mistake in the if statement if (x=y) D=4; Z=45; C=12; else D=2; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
51 Common mistake in the if statement if (x=y) D=4; Z=45; C=12; else D=2; the value of D is always 4, except the case when y=0 Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
52 Common mistake in the if statement if (x=y) D=4; Z=45; C=12; else D=2; the value of D is always 4, except the case when y=0 someone used assignment operator (=) instead of comparison (==) Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
53 Short form of if- statement if expression this part is executed only if expression is true Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
54 Short form of if- statement if expression this part is executed only if expression is true if won a million go party Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
55 Short form of if- statement if expression this part is executed only if expression is true if won a million go party if (deviation<=0) exit; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
56 The while statement while expression this part is executed while expression is true Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
57 The while statement while expression this part is executed while expression is true while hungry keep eating Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
58 The while statement while expression this part is executed while expression is true while hungry keep eating i=1; while (i<=10) c=a+b; z=c*4+5; i=i+2; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
59 The while statement while expression this part is executed while expression is true while hungry keep eating i=1; while (i<=10) c=a+b; z=c*4+5; i=i+2; while loop is extremely useful but they are not guaranteed to finish. For a bit more complicated conditional statement and loop it is impossible to predict if the loop will finish. Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
60 The while statement while expression this part is executed while expression is true while hungry keep eating i=1; while (i<=10) c=a+b; z=c*4+5; i=i+2; while loop is extremely useful but they are not guaranteed to finish. For a bit more complicated conditional statement and loop it is impossible to predict if the loop will finish. Yet another common mistake is i=1; while (i<=10) c=a+b; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
61 The while statement while expression this part is executed while expression is true while hungry keep eating i=1; while (i<=10) c=a+b; z=c*4+5; i=i+2; while loop is extremely useful but they are not guaranteed to finish. For a bit more complicated conditional statement and loop it is impossible to predict if the loop will finish. Yet another common mistake is i=1; while (i<=10) c=a+b; not updating the term leading to fulfillment of the while condition Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
62 The for statement for variable = expression do something In this case variable is assigned concequently with columns of the expression, and then statements inside of the loop are executed Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
63 The for statement for variable = expression do something In this case variable is assigned concequently with columns of the expression, and then statements inside of the loop are executed sum=0; x=[1,3,5,6] for v=x sum=sum+v; >> sum sum = 15 Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
64 The for statement for variable = expression do something In this case variable is assigned concequently with columns of the expression, and then statements inside of the loop are executed sum=0; x=[1,3,5,6] for v=x sum=sum+v; >> sum sum = 15 for loops are guaranteed to complete after predictable number of iterations (the amount of columns in expression). Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
65 Example 100 S = i = i=1 Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
66 Example 100 S = i = i=1 S=0; i=1; while(i<=100) S=S+i; i=i+1; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
67 Example 100 S = i = i=1 S=0; i=1; while(i<=100) S=S+i; i=i+1; S=0; for i=1:100 S=S+i; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
68 Example S = k=1 a k Until k<=100 and a k < 10 5, where a k = k k. Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
69 Example S = k=1 a k Until k<=100 and a k < 10 5, where a k = k k. S=0; k=1; while( (k<=100) & (k^-k >= 1e-5) ) S=S+k^-k; k=k+1; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
70 Example S = k=1 a k Until k<=100 and a k < 10 5, where a k = k k. S=0; k=1; while( (k<=100) & (k^-k >= 1e-5) ) S=S+k^-k; k=k+1; >> S S = Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
71 Example S = k=1 a k Until k<=100 and a k < 10 5, where a k = k k. S=0; k=1; while( (k<=100) & (k^-k >= 1e-5) ) S=S+k^-k; k=k+1; >> S S = S=0; k=1; while( k<=100 ) a_k=k^-k; if (a_k < 1e-5) break; S=S+a_k; k=k+1; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
72 Example S = k=1 a k Until k<=100 and a k < 10 5, where a k = k k. S=0; k=1; while( (k<=100) & (k^-k >= 1e-5) ) S=S+k^-k; k=k+1; >> S S = S=0; k=1; while( k<=100 ) a_k=k^-k; if (a_k < 1e-5) break; S=S+a_k; k=k+1; >> S S = Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
73 Same example with for loop S = k=1 a k Until k<=100 and a k < 10 5, where a k = k k. Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
74 Same example with for loop S = k=1 a k Until k<=100 and a k < 10 5, where a k = k k. S=0; for k=1:100 a_k=k^-k; if (a_k < 1e-5) break; S=S+a_k; Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
75 Same example with for loop S = k=1 a k Until k<=100 and a k < 10 5, where a k = k k. S=0; for k=1:100 a_k=k^-k; if (a_k < 1e-5) break; S=S+a_k; >> S S = Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
76 Interest rate related example Suppose bank gave you 50% interest rate (let s call it x ), and you put one dollar in. How much would you get at the of the year? one payment at the of the year M 1 = 1 (1 + x) = 1 (1 +.5) = 1.5 Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
77 Interest rate related example Suppose bank gave you 50% interest rate (let s call it x ), and you put one dollar in. How much would you get at the of the year? one payment at the of the year M 1 = 1 (1 + x) = 1 (1 +.5) = 1.5 interest payment every half a year M 2 = 1 (1 + x/2) (1 + x/2) = 1 (1 +.5/2) 2 = Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
78 Interest rate related example Suppose bank gave you 50% interest rate (let s call it x ), and you put one dollar in. How much would you get at the of the year? one payment at the of the year M 1 = 1 (1 + x) = 1 (1 +.5) = 1.5 interest payment every half a year M 2 = 1 (1 + x/2) (1 + x/2) = 1 (1 +.5/2) 2 = interest payment every month M 12 = 1 (1 + x/12) 12 = Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
79 Interest rate related example Now let s find how you money growth (M N ) deps on the number of payments per year N_max=100; N=1:N_max; M=0*(N); x=.5; for i=n M(i)=(1+x/i)^i; plot(n,m, - ); xlabel( N, number of payments per year ); ylabel( Money grows ); title( Money grows vs number of payments per year ); Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
80 Interest rate related example Eugeniy Mikhailov (W&M) Practical Computing Lecture / 19
Functions and scripts
Functions and scripts Eugeniy E. Mikhailov The College of William & Mary Lecture 04 Eugeniy Mikhailov (W&M) Practical Computing Lecture 04 1 / 14 Scripts Script is the sequence of the Matlab expressions
More informationSorting. Bubble sort method. Bubble sort properties. Quick sort method. Notes. Eugeniy E. Mikhailov. Lecture 27. Notes. Notes
Sorting Eugeniy E. Mikhailov The College of William & Mary Lecture 7 Eugeniy Mikhailov (W&M) Practical Computing Lecture 7 1 / 18 Bubble sort method Some one give us a vector of unsorted numbers. We want
More informationIntroduction to Matlab. Matlab variable types. Matlab variable types. Matlab variable types. Notes. Eugeniy E. Mikhailov. Lecture 02. Notes.
Introduction to Matlab Eugeniy E. Mikhailov The College of William & Mary Lecture 02 Eugeniy Mikhailov (W&M) Practical Computing Lecture 02 1 / 26 Matlab variable types Eugeniy Mikhailov (W&M) Practical
More informationIntroduction to Matlab
Introduction to Matlab Eugeniy E. Mikhailov The College of William & Mary Lecture 02 Eugeniy Mikhailov (W&M) Practical Computing Lecture 02 1 / 27 Matlab variable types Eugeniy Mikhailov (W&M) Practical
More informationSYNERGY INSTITUTE OF ENGINEERING & TECHNOLOGY,DHENKANAL LECTURE NOTES ON DIGITAL ELECTRONICS CIRCUIT(SUBJECT CODE:PCEC4202)
Lecture No:5 Boolean Expressions and Definitions Boolean Algebra Boolean Algebra is used to analyze and simplify the digital (logic) circuits. It uses only the binary numbers i.e. 0 and 1. It is also called
More informationObjectives: 1- Bolean Algebra. Eng. Ayman Metwali
Objectives: Chapter 3 : 1- Boolean Algebra Boolean Expressions Boolean Identities Simplification of Boolean Expressions Complements Representing Boolean Functions 2- Logic gates 3- Digital Components 4-
More informationCOMP Intro to Logic for Computer Scientists. Lecture 2
COMP 1002 Intro to Logic for Computer Scientists Lecture 2 B 5 2 J Language of logic: building blocks Proposition: A sentence that can be true or false. A: It is raining in St. John s right now. B: 2+2=7
More informationConcepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.
Concepts Review 1. An algorithm is a sequence of steps to solve a problem. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++. 3. A flowchart is the graphical
More informationLecture Transcript While and Do While Statements in C++
Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some
More informationLecture 3: Binary Subtraction, Switching Algebra, Gates, and Algebraic Expressions
EE210: Switching Systems Lecture 3: Binary Subtraction, Switching Algebra, Gates, and Algebraic Expressions Prof. YingLi Tian Feb. 5/7, 2019 Department of Electrical Engineering The City College of New
More informationLoops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala
Loops and Conditionals HORT 59000 Lecture 11 Instructor: Kranthi Varala Relational Operators These operators compare the value of two expressions and returns a Boolean value. Beware of comparing across
More informationLecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18
Assignment Lecture 9 Logical Operations Formatted Print Printf Increment and decrement Read through 3.9, 3.10 Read 4.1. 4.2, 4.3 Go through checkpoint exercise 4.1 Logical Operations - Motivation Logical
More informationComputer Project #2 (Matrix Operations)
Math 0280 Introduction to Matrices and Linear Algebra Fall 2006 Computer Project #2 (Matrix Operations) SCHEDULE: This assignment is due in class on Monday, October 23, 2006. One submission per group is
More informationAdvanced Software Testing Understanding Code Coverage
Advanced Software Testing Understanding Code Coverage Advanced Software Testing A series of webinars, this one excerpted from Advanced Software Testing: V3, a book for technical test analysts, programmers,
More informationA gentle introduction to Matlab
A gentle introduction to Matlab The Mat in Matlab does not stand for mathematics, but for matrix.. all objects in matlab are matrices of some sort! Keep this in mind when using it. Matlab is a high level
More informationSimulated annealing/metropolis and genetic optimization
Simulated annealing/metropolis and genetic optimization Eugeniy E. Mikhailov The College of William & Mary Lecture 18 Eugeniy Mikhailov (W&M) Practical Computing Lecture 18 1 / 8 Nature s way to find a
More informationCSE 143. Computer Programming II
Adam Blank Lecture 17 Winter 2015 CSE 143 Computer Programming II CSE 143: Computer Programming II Recursive Backtracking Recursive Backtracking Outline 1 Sentence Splitter 2 Playing With Boolean Expressions
More informationLecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan
Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful
More informationFlow of Control: Loops
Flow of Control: Loops Chapter 4 Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks Use repetition in a graphics program Use drawstring
More informationbool bool - either true or false
Strings & Branching bool bool - either true or false You have the common math comparisons: > (greater than), e.g. 7 > 2.5 is true == (equals), e.g. 5 == 4 is false
More informationAnnouncements. Project 5 is on the street. Second part is essay questions for CoS teaming requirements.
Announcements Project 5 is on the street. Second part is essay questions for CoS teaming requirements. The first part you do as a team The CoS essay gets individually answered and has separate submission
More informationActivity Boolean Algebra
Activity 2.1.6 Boolean Algebra Introduction Have you ever had an idea that you thought was so unique that when you told someone else about it, you simply could not believe they thought you were wasting
More informationHaskell Review COMP360
Haskell Review COMP360 Some people talk in their sleep. Lecturers talk while other people sleep Albert Camus Remaining Schedule Friday, April 7 Haskell Monday, April 10 Logic Programming read chapter 12
More informationStructure Array 1 / 50
Structure Array A structure array is a data type that groups related data using data containers called fields. Each field can contain any type of data. Access data in a structure using dot notation of
More informationControl Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28
Control Structures Dr. Mihail March 1, 2015 (Dr. Mihail) Control March 1, 2015 1 / 28 Overview So far in this course, MATLAB programs consisted of a ordered sequence of mathematical operations, functions,
More informationPropositional Logic:
CS2209A 2017 Applied Logic for Computer Science Lecture 2 Propositional Logic: Syntax, semantics, truth table Instructor: Yu Zhen Xie Language of logic: building blocks Proposition: A sentence that can
More informationCS470: Computer Architecture. AMD Quad Core
CS470: Computer Architecture Yashwant K. Malaiya, Professor malaiya@cs.colostate.edu AMD Quad Core 1 Architecture Layers Building blocks Gates, flip-flops Functional bocks: Combinational, Sequential Instruction
More informationChapter 4: Programming with MATLAB
Chapter 4: Programming with MATLAB Topics Covered: Programming Overview Relational Operators and Logical Variables Logical Operators and Functions Conditional Statements For Loops While Loops Debugging
More informationLogic-based test coverage
Eduardo Marques, Vasco Thudichum Vasconcelos Logic-based test coverage Basic approach Clauses and predicates Basic coverage criteria: CC, PC, CoC Structural logic coverage of source code Logic coverage
More informationOther useful tools. Eugeniy E. Mikhailov. Lecture 11. The College of William & Mary. Eugeniy Mikhailov (W&M) Practical Computing Lecture 11 1 / 9
Other useful tools Eugeniy E. Mikhailov The College of William & Mary Lecture 11 Eugeniy Mikhailov (W&M) Practical Computing Lecture 11 1 / 9 Specialization is... A human being should be able to change
More informationCS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started
CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started Handout written by Julie Zelenski, Mehran Sahami, Robert Plummer, and Jerry Cain. After today s lecture, you should run home and read
More informationFlow of Control: Loops. Objectives. Java Loop Statements: Outline 6/27/2014. Chapter 4
Flow of Control: Loops Chapter 4 Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks Use repetition in a graphics program Use drawstring
More informationFlow Control: Branches and loops
Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the
More information(Refer Slide Time 3:31)
Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 5 Logic Simplification In the last lecture we talked about logic functions
More informationCS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM
CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM This handout explains what you have to know for the first prelim. Terms and their meaning Below, we summarize the terms you should
More informationENGIN 112 Intro to Electrical and Computer Engineering
ENGIN 2 Intro to Electrical and Computer Engineering Lecture 5 Boolean Algebra Overview Logic functions with s and s Building digital circuitry Truth tables Logic symbols and waveforms Boolean algebra
More information(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))
ComS 207: Programming I Midterm 2, Tue. Mar 21, 2006 Student Name: Student ID Number: Recitation Section: 1. True/False Questions (10 x 1p each = 10p) Determine the value of each boolean expression given
More informationQUESTION BANK FOR TEST
CSCI 2121 Computer Organization and Assembly Language PRACTICE QUESTION BANK FOR TEST 1 Note: This represents a sample set. Please study all the topics from the lecture notes. Question 1. Multiple Choice
More informationRecitation Session 6
Recitation Session 6 CSE341 Computer Organization University at Buffalo radhakri@buffalo.edu March 11, 2016 CSE341 Computer Organization Recitation Session 6 1/26 Recitation Session Outline 1 Overview
More informationMenu. Algebraic Simplification - Boolean Algebra EEL3701 EEL3701. MSOP, MPOS, Simplification
Menu Minterms & Maxterms SOP & POS MSOP & MPOS Simplification using the theorems/laws/axioms Look into my... 1 Definitions (Review) Algebraic Simplification - Boolean Algebra Minterms (written as m i ):
More informationObject-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018
Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative
More informationMath 1526: Excel Lab 5 Summer 2004
Math 5: Excel Lab 5 Summer Matrix Algebra In order to complete matrix operations using Excel, you must learn how to use arrays. First you must learn how to enter a matrix into a spreadsheet. For practice,
More informationUnit 7. 'while' Loops
1 Unit 7 'while' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment
More informationFall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB
Fall 2014 MAT 375 Numerical Methods Introduction to Programming using MATLAB Some useful links 1 The MOST useful link: www.google.com 2 MathWorks Webcite: www.mathworks.com/help/matlab/ 3 Wikibooks on
More informationSTUDENT LESSON A14 Boolean Algebra and Loop Boundaries
STUDENT LESSON A14 Boolean Algebra and Loop Boundaries Java Curriculum for AP Computer Science, Student Lesson A14 1 STUDENT LESSON A14 Boolean Algebra and Loop Boundaries INTRODUCTION: Conditional loops
More informationProject 2: How Parentheses and the Order of Operations Impose Structure on Expressions
MAT 51 Wladis Project 2: How Parentheses and the Order of Operations Impose Structure on Expressions Parentheses show us how things should be grouped together. The sole purpose of parentheses in algebraic
More informationMATH 676. Finite element methods in scientific computing
MATH 676 Finite element methods in scientific computing Wolfgang Bangerth, Texas A&M University Lecture 41.25: Parallelization on a cluster of distributed memory machines Part 2: Debugging with MPI Debugging
More informationAMS 27L LAB #2 Winter 2009
AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles
More informationChapter 2 Operations and Expressions
Chapter Operations and Expressions Homework.. Substitute for x in x. Substitute for x in x. Substitute for x in x 9 : : : 9 8. Substitute for x in 0 x : 0 0. Substitute for x in x x. Substitute for x in
More informationAnnouncements. HW 0 due tonight (check that it compiles on CSE labs) (make sure you submit the code part)
Loops Ch 3.3-3.4 Announcements HW 0 due tonight (check that it compiles on CSE labs) (make sure you submit the code part) Scope (See last time: scope.cpp) If... if... else! When in doubt, use parenthesis
More informationFinite Math - J-term Homework. Section Inverse of a Square Matrix
Section.5-77, 78, 79, 80 Finite Math - J-term 017 Lecture Notes - 1/19/017 Homework Section.6-9, 1, 1, 15, 17, 18, 1, 6, 9, 3, 37, 39, 1,, 5, 6, 55 Section 5.1-9, 11, 1, 13, 1, 17, 9, 30 Section.5 - Inverse
More informationDCS/100: Procedural Programming
DCS/100: wk 5 p.1/33 DCS/100: Procedural Programming Week 5: While Loops Queen Mary, University of London DCS/100: wk 5 p.2/33 Last week You should now be able to: write programs that follow instructions
More informationAnnouncements. Lab 1 this week! Homework posted Wednesday (late)
C++ Basics Announcements Lab 1 this week! Homework posted Wednesday (late) Avoid errors To remove your program of bugs, you should try to test your program on a wide range of inputs Typically it is useful
More information4. Flow of Control: Loops
4. Flow of Control: Loops Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives n Design a loop n Use while, and for in a program Java Loop Statements
More information4. Flow of Control: Loops. Objectives. Java Loop Statements 10/10/12. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich
4. Flow of Control: Loops Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives n Design a loop n Use while, and for in a program Java Loop Statements
More information(Refer Slide Time 04:53)
Programming and Data Structure Dr.P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 26 Algorithm Design -1 Having made a preliminary study
More informationHenry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012
Henry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012 1 Digital vs Analog Digital signals are binary; analog
More informationAnnouncements. HW0 is posted on schedule, due next Friday at 9pm (pretty easy)
Branching Announcements HW0 is posted on schedule, due next Friday at 9pm (pretty easy) Office hours (attempt problems before going): - HW only or Lab only (check calendar) - Write name on whiteboard if
More informationIEEE Floating-Point Representation 1
IEEE Floating-Point Representation 1 x = ( 1) s M 2 E The sign s determines whether the number is negative (s = 1) or positive (s = 0). The significand M is a fractional binary number that ranges either
More informationIntroduction in MATLAB (TSRT04)
VT2 2019 Division of Communication Systems Department of Electrical Engineering (ISY) Linköping University, Sweden www.commsys.isy.liu.se/en/student/kurser/tsrt04 About the Course MATLAB Basics Vectors
More informationComputers and programming languages introduction
Computers and programming languages introduction Eugeniy E. Mikhailov The College of William & Mary Lecture 01 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 1 / 19 Class goals and structure Primary
More informationLecture 8. Divided Differences,Least-Squares Approximations. Ceng375 Numerical Computations at December 9, 2010
Lecture 8, Ceng375 Numerical Computations at December 9, 2010 Computer Engineering Department Çankaya University 8.1 Contents 1 2 3 8.2 : These provide a more efficient way to construct an interpolating
More informationChapter 2 Exploring Data with Graphs and Numerical Summaries
Chapter 2 Exploring Data with Graphs and Numerical Summaries Constructing a Histogram on the TI-83 Suppose we have a small class with the following scores on a quiz: 4.5, 5, 5, 6, 6, 7, 8, 8, 8, 8, 9,
More informationShuli s Math Problem Solving Column
huli s Math Problem olving Column Volume, Issue March, 009 Edited and uthored by huli ong Colorado prings, Colorado shuli_song@yahoo.com Content. Math Trick: Mental Calculation: aa bc. Math Competition
More informationENGINEERS ACADEMY. 7. Given Boolean theorem. (a) A B A C B C A B A C. (b) AB AC BC AB BC. (c) AB AC BC A B A C B C.
Digital Electronics Boolean Function QUESTION BANK. The Boolean equation Y = C + C + C can be simplified to (a) (c) A (B + C) (b) AC (d) C. The Boolean equation Y = (A + B) (A + B) can be simplified to
More informationfor all x, the assertion P(x) is false. there exists x, for which the assertion P(x) is true.
You can t prove a predicate is true because a predicate is not an assertion, you can t prove it is valid as it is not a deduction! If someone asks you to prove P(x), it is not totally clear what they mean.
More information4. Flow of Control: Loops. Objectives. Java Loop Statements: Outline 10/3/11. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich
4. Flow of Control: Loops Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives! Design a loop! Use while, and for in a program Java Loop Statements:
More information4. Flow of Control: Loops
4. Flow of Control: Loops Prof. Dr. Harald Gall Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch Objectives Design a loop Use while, and for in a program Java Loop Statements: Outline
More informationFiles and File Management Scripts Logical Operations Conditional Statements
Files and File Management Scripts Logical Operations Conditional Statements Files and File Management Matlab provides a group of commands to manage user files pwd: Print working directory displays the
More informationOrdinary Differential Equation Solver Language (ODESL) Reference Manual
Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE
More information8.3 Common Loop Patterns
Lecture 17 Topics: Chapter 8. Loop Structures and Booleans 8.3 (Continues) nested loops 8.4. Computing with booleans 8.5 Other common structures: post-test, loop and half. 1 8.3 Common Loop Patterns Nested
More informationComputational Mathematics
Computational Mathematics Hilary Term Lecture 1: Programming Andrew Thompson Outline for Today: Schedule this term Review Introduction to programming Examples Arrays: the foundation of MATLAB Basics MATLAB
More informationCS 112: Intro to Comp Prog
CS 112: Intro to Comp Prog Importing modules Branching Loops Program Planning Arithmetic Program Lab Assignment #2 Upcoming Assignment #1 Solution CODE: # lab1.py # Student Name: John Noname # Assignment:
More informationFrom: Robert Sharpley Subject: Homeworks #6 Date: February 22, :09:53 AM EST Cc: Robert Sharpley
From: Robert Sharpley Subject: Homeworks #6 Date: February 22, 2006 9:09:53 AM EST Cc: Robert Sharpley %% Homework #5 - Solutions %% Here is a matlab code
More information18.02 Multivariable Calculus Fall 2007
MIT OpenCourseWare http://ocw.mit.edu 18.02 Multivariable Calculus Fall 2007 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 18.02 Problem Set 4 Due Thursday
More informationChapter 3. Boolean Algebra and Digital Logic
Chapter 3 Boolean Algebra and Digital Logic Chapter 3 Objectives Understand the relationship between Boolean logic and digital computer circuits. Learn how to design simple logic circuits. Understand how
More informationPIC 10A Flow control. Ernest Ryu UCLA Mathematics
PIC 10A Flow control Ernest Ryu UCLA Mathematics If statement An if statement conditionally executes a block of code. # include < iostream > using namespace std ; int main () { double d1; cin >> d1; if
More informationStatistical Computing (36-350)
Statistical Computing (36-350) Lecture 3: Flow Control Cosma Shalizi and Vincent Vu 7 September 2011 Agenda Conditionals: Switching between doing different things Iteration: Doing similar things many times
More informationCIS 110: Introduction to Computer Programming
CIS 110: Introduction to Computer Programming Lecture 14 Booleans and Program Assertions ( 5.3-5.5) 10/26/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline The boolean primitive type Program assertions
More informationDiscrete structures - CS Fall 2017 Questions for chapter 2.1 and 2.2
Discrete structures - CS1802 - Fall 2017 Questions for chapter 2.1 and 2.2 1. (a) For the following switch diagrams, write the corresponding truth table and decide whether they correspond to one of the
More informationLecture 8: Iterators and More Mutation
Integrated Introduction to Computer Science Fisler, Nelson Contents 1 Traversing Lists 1 2 Motivating Iterators 2 3 Writing an Iterator 3 4 Writing Sum with an Iterator 4 Objectives By the end of this
More informationA QUICK INTRODUCTION TO MATLAB
A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally
More informationIntroduction to MATLAB
Introduction to MATLAB --------------------------------------------------------------------------------- Getting MATLAB to Run Programming The Command Prompt Simple Expressions Variables Referencing Matrix
More informationIntroduction to Engineering gii
25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.
More informationIteration: Intro. Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times. 2. Posttest Condition follows body Iterates 1+ times
Iteration: Intro Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times 2. Posttest Condition follows body Iterates 1+ times 1 Iteration: While Loops Pretest loop Most general loop construct
More informationLie, Cheat and Deceive: Change the Rules of Cyber Defense
SESSION ID: SPO-W10A Lie, Cheat and Deceive: Change the Rules of Cyber Defense Sameh Sabry Associate Vice President Professional Services Spire Solutions Why continue to do things the way we always have?
More information1 #include <iostream > 3 using std::cout; 4 using std::cin; 5 using std::endl; 7 int main(){ 8 int x=21; 9 int y=22; 10 int z=5; 12 cout << (x/y%z+4);
2 3 using std::cout; 4 using std::cin; using std::endl; 6 7 int main(){ 8 int x=21; 9 int y=22; int z=; 11 12 cout
More informationLecture 2 Selection and Looping. Program control, if-else, logical expressions, for loop
Lecture 2 Selection and Looping Program control, if-else, logical expressions, for loop Overview Review Program control if-else statement Relational and logical operators Logical expressions for loop statement
More informationLoop structures and booleans
Loop structures and booleans Michael Mandel Lecture 7 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture07final.ipynb
More informationShort Version of Matlab Manual
Short Version of Matlab Manual This is an extract from the manual which was used in MA10126 in first year. Its purpose is to refamiliarise you with the matlab programming concepts. 1 Starting MATLAB 1.1.1.
More informationA QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started
A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered
More informationCSE 373: Data Structures and Algorithms
CSE 373: Data Structures and Algorithms Lecture 17: Finish Dijkstra s Algorithm, Preserving Abstractions (Software Design), Spanning Trees Instructor: Lilian de Greef Quarter: Summer 2017 Today Wrap up
More informationPost PC Era: Mobile Banking & Payments in Emerging Markets. Report Covers: India, Kenya, Indonesia, Ghana and Nigeria
Post PC Era: Mobile Banking & Payments in Emerging Markets Report Covers: India, Kenya, Indonesia, Ghana and Nigeria In emerging markets, formal banking only reaches a small percent of the population,
More informationLSN 4 Boolean Algebra & Logic Simplification. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology
LSN 4 Boolean Algebra & Logic Simplification Department of Engineering Technology LSN 4 Key Terms Variable: a symbol used to represent a logic quantity Compliment: the inverse of a variable Literal: a
More informationLecture. Loops && Booleans. Richard E Sarkis CSC 161: The Art of Programming
Lecture Loops && Booleans Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda (In-)definite loops (for/while) Patterns: interactive loop and sentinel loop Solve problems using (possibly
More informationAnnouncements. Homework 0: using cin with 10/3 is NOT the same as (directly)
Branching Announcements Homework 0: using cin with 10/3 is NOT the same as 3.3333 (directly) With cin, it will stop as soon as it reaches a type that does not match the variable (into which it is storing)
More informationBig-step Operational Semantics (aka Natural Semantics)
x = 1 let x = 1 in... x(1).!x(1) x.set(1) Programming Language Theory Big-step Operational Semantics (aka Natural Semantics) Ralf Lämmel A big-step operational semantics for While 2 This slide is derived
More informationCSCI Wednesdays: 1:25-2:15 Keller Thursdays: 4:00-4:50 Akerman 211
C++ Basics CSCI 1113 Wednesdays: 1:25-2:15 Keller 1-250 Thursdays: 4:00-4:50 Akerman 211 Peer-assisted Learning sessions - PAL Weekly practice with course concepts Work with peers to reinforce understanding
More informationSingular Value Decomposition, and Application to Recommender Systems
Singular Value Decomposition, and Application to Recommender Systems CSE 6363 Machine Learning Vassilis Athitsos Computer Science and Engineering Department University of Texas at Arlington 1 Recommendation
More informationQuiz Determine the output of the following program:
Quiz Determine the output of the following program: 1 Structured Programming Using C++ Lecture 4 : Loops & Iterations Dr. Amal Khalifa Dr. Amal Khalifa - Spring 2012 1 Lecture Contents: Loops While do-while
More information