Structured Programming I – Relational & Logical Operators Objectives: By the end of this class you should be able to: Change graph interactively in EXCEL.

Slides:



Advertisements
Similar presentations
A number of MATLAB statements that allow us to control the order in which statements are executed in a program. There are two broad categories of control.
Advertisements

STROUD Worked examples and exercises are in the text PROGRAMME F4 GRAPHS.
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 1 1 Microsoft Office Excel 2003.
Understanding Microsoft Excel
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Decision-Making Programs
Excel Lesson 4 Entering Worksheet Formulas
Using Excel for Data Analysis in CHM 161 Monique Wilhelm.
Class 9.1 Chapter 4 Sections: 4.1, 4.2, 4.3
Lab 09 More on Spreadsheets MS Excel. Objectives  The students should understand and have hands on experience in Working with formulas and functions.
Today’s quiz on 8.2 A Graphing Worksheet 1 will be given at the end of class. You will have 12 minutes to complete this quiz, which will consist of one.
CS1100: Computer Science and Its Applications Creating Graphs and Charts in Excel.
Excel Web App By: Ms. Fatima Shannag.
Spreadsheets Objective 6.02
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
2 Explain advanced spreadsheet concepts and functions Advanced Calculations 1 Sabbir Saleh_Lecture_17_Computer Application_BBA.
Akil M. Merchant CGS 2060 – Spring 2011 For Dr. David Gaitros CGS Spring Continuing to Excel with Excel.
Computer Literacy BASICS
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Microsoft Excel Part 2 Kin 260 Adapted from Daniel Frankl, Ph.D. Revised by Jackie Kiwata 10/07.
Microsoft Excel By: Dr. K.V. Vishwanath Professor, Dept. of C.S.E,
 Introduction to MS-Excel Introduction to MS-Excel  Entering data in EXCEL Entering data in EXCEL  Formulas & Functions in EXCEL Formulas & Functions.
Excel Worksheet # 5 Class Agenda Formulas & Functions
Excel Spreadsheet basics. Excel Sheets and Books  Spreadsheet: tool to analyze, chart and manage data for personal, business and financial use Worksheet:
Data Presentation & Graphing Introduction to Mechanical Engineering The University of Texas-Pan American College of Science and Engineering.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 1 Copyright © 2008 Prentice-Hall. All rights reserved. What Can I Do with a Spreadsheet.
Chapter 2 Excel Review.
Excel Project 2 Formulas, Functions, and Formatting.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Ch.1. Spread Basics I. Goals: 1)Basic purpose of a spreadsheet program 2)Various components of the Excel screen 3)Navigating the worksheet 4)Built-in functions.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Excel Ch 4 Review.
Microsoft Excel Using Excel to Graph Data Juliana YamNovember 14, 2006.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Excel Web App By: Ms. Fatima Shannag.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Excel 2007 Part (3) Dr. Susan Al Naqshbandi
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
Overview Excel is a spreadsheet, a grid made from columns and rows. It is a software program that can make number manipulation easy and somewhat painless.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
December 2015 Excel Tips & Tricks. Commonly Used Shortcuts (Mac, Excel 2011) Cmd+ Shift+ T Enter Cmd+ Option+ 0 Ctrl+ (Minus/- ) Ctrl+ I Ctrl+ R or Ctrl+
STROUD Worked examples and exercises are in the text 1 STROUD Worked examples and exercises are in the text Programme F4: Graphs PROGRAMME F4 GRAPHS.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Resource Review Excel formula basics Demonstrate how to enter manual formulas Examine some of the available functions and their usage Discuss the.
Relational and Logical Operators EE 201 1C7-2 Spring 2012.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Formulas, Functions, and other Useful Features
ECE 1304 Introduction to Electrical and Computer Engineering
How to Make a Graph for a Biology Lab
Microsoft Excel.
Created by Stacey Wilson
MATLAB: Structures and File I/O
Unit 7 – Excel Graphs.
Chapter 8 JavaScript: Control Statements, Part 2
Microsoft Excel 101.
Class 9.1 Chapter 4 Sections: 4.1, 4.2, 4.3
INTRODUCTION TO MATLAB
Spreadsheets 2 Explain advanced spreadsheet concepts and functions
Spreadsheets Objective 6.02
Matlab Basics.
Spreadsheets Objective 6.02
By the end of the lesson, I want you to be able to say…
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

Structured Programming I – Relational & Logical Operators Objectives: By the end of this class you should be able to: Change graph interactively in EXCEL define the key terms in logical statements including: –relational operators, –logical operators, –1 and 0 as true and false determine the truth of relational statements determine the truth of relational statements using logical operators text sections: 4.2 & 4.3

Quiz – individual please The equation for an ellipse can be written as follows: Develop a script that can plot an ellipse on Cartesian axes with axes of a = 5 m and b=10 m. where a, b are the major and minor axis lengths of the ellipsis and  varies from zero to 2 . Make sure that the real geometry of the ellipses is shown, i.e., a circle should look like a circle. Please print out your script and the resulting graph.

Changing Graph Interactively in Excel interactive options – try: Right Click on the Axes and choose “Format Axis” note the options –you can change ranges, tick spacing... –you can also choose log spacing for any axis –you can change the position of the axis numbers. Click on the series –set points, lines and colors Click on titles –to edit and change fonts – use home ribbon. Click on blank area of graph –If in 03 get rid of the gray background

Putting a function on the graph plot the fit to our data: the fitted equation was ht=29 – 0.028*raw. need some x values (what range): Create an x series in spreadsheet (a column of x values) – can use one of the existing series. add a formula to the first cell in the next column and copy down to to create y series. add this series to graph as before. click on the series and change to lines instead of points.

Excel: Some Potential pitfalls The line graph: –start the graph wizard and choose line graph –select one set of x-y data –plot the points –Result: the points are plotted in order with no other meaning to the x axis. Trying to plot all at once –highlight the entire block of data –start plot wizard and create an x-y plot –Result: all series are plotted against the first series – not really what we wanted. You can plot multiple series at once but only when the first is the x values for all series and the remaining columns are matching y-series

Relational Operators greater than = less than or equal == equal  must be distinguished from the assignment operator ~= not equal summarized in Table in text

Scalar comparison For x = 6 try z= (x < 10) z=(x==10) z=(x>=4) z=(x~=7) Notice class of z in workspace window

Handout: Relational and Logical Operators Handout Have students break into pairs for the problems that follow. Have students refer to as they work on the following examples

Scalar to a Vector  Result: logical vector (array) same size as original  Compares the scalar to each value in the vector  Returns a true or false for each comparison e.g., >> y = (2 >= [ 1 2 3]) y = [1 1 0] (true, true, false)

Scalar to a Vector Problem A stock price history over 10 days is: price_A = [ 19, 18, 22, 21, 25, 19, 17, 21, 27, 29 ]; Use MATLAB to calculate the number of days were the price is over 20. Can you do this in one line of MATLAB code?

Scalar to Vector Comparison Set up vector and compare to scalar boundary >> price_A = [19, 18, 22, 21, 25, 19, 17, 21, 27, 29]; >> z = price_A > 20 z = Notice the vector shows us which days meet the condition. We can simply sum this vector to find the number of days. >> sum(z) ans = 6 In one line >> sum(price_A > 20) ans = 6

Logical Comparison of Two Vectors  Two vectors must be the same length  Results in a logical vector of the same length  Compares the two vectors element by element e.g. z = ([1 2 3] ~= [3 2 1] )  z =[1 0 1] (true, false, true)

Vector vs. Vector Problem price_A = [19, 18, 22, 21, 25, 19, 17, 21, 27, 29] price_B = [22, 17, 20, 19, 24, 18, 16, 25, 28, 27] The arrays price_A and price_B given above contain the price in dollars of two stocks over several days. Use MATLAB to determine how many days the price of stock A was above the price of stock B.

Vector to Vector Comparison Set up vectors and compare, notice price_A is the same as above so we only need to set up vector price_B. >> price_B = [22, 17, 20, 19, 24, 18, 16, 25, 28, 27] price_B = >> z = price_A > price_B z = Again the vector shows us which days meet the condition & we can use sum to find the number of days. >> sum(z) ans = 7 In one line: >> sum(price_A > price_B)

Text Comparisons Create variables: a = ‘o’, b=‘Mastodons’, c=‘mastodons’ Try the following comparisons x = (b == a) y = (b == c) z = (b < c) text strings  can be defined by enclosing in single quotes (literals)  vectors of type char  ASCII value is compared

text comparisons: MATLAB session > a = 'o'; b='Mastodons'; c='mastodons'; >> x = (b == a) x = >> y = (b == c) y = >> z = (b < c) z = notice >> double('M'), double('m') ans = 77 ans = 109 Note: relational operators have equal precedence, L-to-R execution

Basic Logical Operators NameMATLAB operator Function and&true if both connected statements are true or| (shift \) true of either connected statement is true not~ (shift `) makes a true statement false or vise- versa xorxor(A,B)true A & B differ, false if both are the same

Page 2 of Handout Have students try and develop truth table by hand (section III on Handout) Go through the following example truth table Have them follow create a truth table in MATLAB following instructions is section IV of the handout Order of Precedence is Handout section V.

III. Truth Table ABNot ~A Or A | B And A & B Exclusive or XOR(A,B) True(1) True(1))False(0) True(1) False(0) True(1)

IV. Creating Truth Table in MATLAB >> A = [ ]’; % notice a transpose is used >> B = [ ]’; >> Ttable = [A, B, ~A, A | B, A & B, xor(A, B)] Ttable = Matches table in previous slide

V. Order of Precedence 1.Parenthesis () 2.arithmetic and logical NOT +-/* ~ 3.relational operators <>== 4.logical AND & 5.logical OR | last two new with MATLAB 6 and above

Logical of a double vector Try the following >> a = [ -2, 3, 0.001, 0, 4, 0] >> logical(a) What happens when double is converted to logical? Now try >> find(a) What does this do?

Handout part VI. >> x = [-3,0,0,2,5,8]; >> y = [-5,-2,0,3,4,10]; >> z = y <~ x z = >> zb = x & y zb = >> zc = x | y zc = >> zd = xor(x, y) zd = What are the indices of the true values for z in part a. >> zi=find(z) zi = What are the x & y values for the true cases in b. >> x(find(zb)) ans = >> y(find(zb)) ans =

Discuss: Short cut operators – same result, speeds up execution for scalars (not for vectors) –A&&B => if A = 0, evaluates to false immediately –A||B => if A=1, evaluates to true immediately The find function => returns the indices of the nonzero elements e.g., z=find(x&y) … VII. If time allows, review other logical functions from Table –All => many component and –Any => many component if –Ischar, isempty, isinf …