Lecture 3 Sept 3 Complete Chapter 3 Exercises quiz.

Slides:



Advertisements
Similar presentations
Discrete Mathematics Lecture 1 Logic of Compound Statements
Advertisements

Programming Languages and Paradigms The C Programming Language.
CS 100: Roadmap to Computing Fall 2014 Lecture 0.
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
ES 314 Lecture 2 Sep 1 Summary of lecture 1: course overview intro to matlab sections of Chapters 2 and 3.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
Lecture 7 Sept 17 Goals: Complete Chapter 4 Chapters 5 and 6.
Lecture 7 Sept 29 Goals: Chapters 5 and 6. Scripts Sequence of instructions that we may want to run can be stored in a file (known as script). by typing.
To remind us We finished the last day by introducing If statements Their structure was:::::::::
Lecture 7 Sept 19, 11 Goals: two-dimensional arrays (continued) matrix operations circuit analysis using Matlab image processing – simple examples Chapter.
Lecture 3 August 31 Chapter 3. Chapter 3 – numbers, string, booleans integer: MATLAB stores numeric data as double-precision floating point (double) by.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
1.2 – Open Sentences and Graphs
Lecture 7 Sept 29 Goals: Chapters 5 and 6. Chapter 5 - Exercises Exercise 5.2. Write a script swap.m that swaps the values of variables a and b. For example:
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
XOR and XNOR Logic Gates. XOR Function Output Y is TRUE if input A OR input B are TRUE Exclusively, else it is FALSE. Logic Symbol  Description  Truth.
COMP 116: Introduction to Scientific Programming Lecture 28: Midterm #2 Review.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
EGR 2261 Unit 9 Strings and C-Strings  Read Malik, pages in Chapter 7, and pages in Chapter 8.  Homework #9 and Lab #9 due next week.
Lesson 6-3B Objective: Solve inequalities using more than one step…continued.
Lecture 7 Sept 22 Goals: Chapters 5 and 6. Scripts Sequence of instructions that we may want to run can be stored in a file (known as script). by typing.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
1 REVIEW 1 EXAM 3. Question 1 Which statement(s) is/are valid to create a string? a. x = “EGR 115” □ Valid □ Invalid b. x = ‘EGR 115’ □ Valid □ Invali.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Thinking Mathematically
Chapter 51 Decisions Relational and Logical Operators If Blocks Select Case Blocks.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
Chapter Making Decisions 4. Relational Operators 4.1.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 4 Making Decisions.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
1-5 Open Sentences Objective: To solve open sentences by performing arithmetic operations.
1. Comparing Strings 2. Converting strings/numbers 3. Additional String Functions Strings Built-In Functions 1.
CN2180 Chapter 4 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP.
Language Find the latest version of this document at
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Interduction to MATLAB (part 2) Manal Alotaibi Mathematics department College of science King saud university.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
Strings Characters and Sentences 1.Overview 2.Creating Strings 3.Slicing Strings 4.Searching for substrings 1.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
CS 139 – Programming Fundamentals Lecture 08A. Relational/comparison Operators Relational Operator Meaning > is greater than < is less than >= is greater.
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
 Type Called bool  Bool has only two possible values: True and False.
Programming Languages and Paradigms
1-5 Equations Goals: Solve equations with one variable
Discrete Mathematics Lecture # 2.
Programming Paradigms
Introduction to MATLAB
C Stuff CS 2308.
Logical Operations In Matlab.
Discrete Mathematics Lecture 2: Propositional Logic
Discrete Mathematics Lecture 2: Propositional Logic
The Data Element.
Nate Brunelle Today: Conditional Decision Statements
Chapter 5 Decisions.
ECS15 boolean.
Truth tables Mrs. Palmer.
The Data Element.
CS 100: Roadmap to Computing
Presentation transcript:

Lecture 3 Sept 3 Complete Chapter 3 Exercises quiz

String operations >> length(greeting) ans = 5 >> strcmp(greeting, ‘hello!’) Ans = 0 ans = 1 if the Boolean expression is true, 0 else. strcmp compares two strings. Strings are case-sensitive. strcat concatenates (glues) strings

String operations strcmp(w1, w2) returns 1 (0) if the strings w1 and w2 are the same. Example: >> a = 'word'; >> b = ['wo', 'rd']; >> strcmp(a, b) ans = 1 >> a == b ans =

String operations strcat (w1, w2) concatenates the strings w1 and w2. Example: >> a = ‘this ’, b = ‘word'; >> c = strcat(a, b); >> c C = ‘thisword’ Strcat removes trailing blanks in the first argument. To avoid this removal, we can use: > c = [a, b];

In general, arrays can be merged using [ ] operation:

String operations A string is stored as a vector of (ASCII) characters. Example: >> str = 'abcdxyz'; >> str+0 ans = ASCII for ‘a’ is 97, for z it is = 122.

Collections of numbers and plotting Two ways to create a vector:

Creating a table of x and y values for plotting A common task is to create the data showing how a variable Y (temp) changes with another variable X (time). Example:

Plot of time vs. temp

Plotting graphs by mathematical relation

Boolean expressions Relational operators:, >=, ~=, == etc. Boolean connectives: & (and) | (or) ~ (not) xor (exclusive or) all any 1 represents TRUE, 0 represents FALSE

Boolean expressions Exercise: Write a one-line statement in MATLAB that returns the number of non- negative members in an array A.

Boolean expressions Exercise: Write a one-line statement in MATLAB that returns the number of non- negative members in an array A. Answer: sum (c >= 0)

Chapter 3 – solutions to some exercises and discussions Dicussion 3.1:

Exercise 3.1: sum(2.^(0 : 4)) Exercise 3.5:

Exercise 3.12:

Exercise 3.12: How many leap years are between 1780 and 2832, inclusive? Recall the definition of a leap year. Exercise 3.8. Write the MATLAB version of the boolean statement a <= b <= c.

Solution to Exercise 3.12: