General Computer Science for Engineers CISC 106 Lecture 13 - Midterm Review James Atlas Computer and Information Sciences 10/02/2009.

Slides:



Advertisements
Similar presentations
How SAS implements structured programming constructs
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
General Computer Science for Engineers CISC 106 Midterm 2 Review James Atlas Computer and Information Sciences 11/06/2009.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Maths for Computer Graphics
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
General Computer Science for Engineers CISC 106 Lecture 02 James Atlas Computer and Information Sciences 6/10/2009.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
General Computer Science for Engineers CISC 106 Final Exam Review Dr. John Cavazos Computer and Information Sciences 05/18/2009.
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
General Computer Science for Engineers CISC 106 Lecture 10 Roger Craig Computer and Information Sciences 3/06/2009.
General Computer Science for Engineers CISC 106 Lecture 25 Dr. John Cavazos Computer and Information Sciences 04/20/2009.
General Computer Science for Engineers CISC 106 Lecture 13 Roger Craig Computer and Information Sciences 3/13/2009.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 9/18/2009.
General Computer Science for Engineers CISC 106 Lecture 09 James Atlas Computer and Information Sciences 9/25/2009.
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
General Computer Science for Engineers CISC 106 Lecture 08 James Atlas Computer and Information Sciences 9/21/2009.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 21P. 1Winter Quarter MATLAB: Structures.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 06/29/2009.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
Tutorial 1SEG7550 Introduction to MATLAB 18 th, SEP
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Matlab Programming, part 1 M-files It is generally more convenient to program in Matlab using m-files, ascii text files containing a set of Matlab commands.
Fall 2006AE6382 Design Computing1 Control Statements in Matlab Topics IF statement and Logical Operators Switch-Case Disp() vs fprintf() Input() Statement.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
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.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 CS1371 Introduction to Computing for Engineers Control Statements 9/4/2003.
General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 2/17/2010.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
General Computer Science for Engineers CISC 106 Lecture 15 Dr. John Cavazos Computer and Information Sciences 03/16/2009.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
Interduction to MATLAB (part 2) Manal Alotaibi Mathematics department College of science King saud university.
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
General Computer Science for Engineers CISC 106 Lecture 14 James Atlas Computer and Information Sciences 08/10/2009.
General Computer Science for Engineers CISC 106 Lecture 05 James Atlas Computer and Information Sciences 6/22/2009.
CS 100Lecture 231 CS100J Lecture 23 n Previous Lecture –MatLab and its implementation, continued. n This Lecture –MatLab demonstration.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 6/15/2009.
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
1 Structured Programming EEN170 Programming in MATLAB.
Flow control. Conditionals if condition do this stuff end if condition do this stuff else do this stuff end if condition do this stuff elseif condition.
General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 9/9/2009.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Computer Application in Engineering Design
CS1371 Introduction to Computing for Engineers
Scripts & Functions Scripts and functions are contained in .m-files
Introduction to MATLAB
Logical Operations In Matlab.
Computer Science Core Concepts
Conditional Statements
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.
CS100A Lecture 21 Previous Lecture This Lecture
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 13 - Midterm Review James Atlas Computer and Information Sciences 10/02/2009

Important Notes on Exam Write code Study labs Study Midterm review

Unix Commands When you log into a UNIX terminal ◦ You are in your home directory. ◦ To see the files in your directory.  ls ◦ To make an new folder/directory.  mkdir exampledir ◦ To change directories.  cd exampledir ◦ To go back one directory.  cd.. ◦ To go back to your home directory.  cd

Basic if statements IF statements allow program to make choices whether a condition is met or not if (expression1) statements1; end if (expression2) statements2; end

IF/Elseif Statements if (expression1) statements1; elseif (expression2) statements2; else statements3; end

Major Relational Operators ◦ A < B A is less than B ◦ A > B A is greater than B ◦ A <= B A is less than or equal to B ◦ A >= B A is greater than or equal to B ◦ A == B A is equal to B ◦ A ~= B A not equal B

If statements print “blue” if N <= 5 print “red” if N > 5 and N <= 10 print “green” if N > 10

If statements (cont’d) if (N <= 5) fprintf('blue\n‘); elseif (N > 5 & N <= 10) fprintf('red\n‘); elseif (N > 10) fprintf('green\n‘); end

Switch construct color = ‘yellow’; switch (color) case ‘red’ disp(‘Stop now!’); case ‘green’ disp(‘Proceed through intersection.’); case ‘yellow’ disp(‘Prepare to stop.’); otherwise disp(‘Illegal color encountered.’); end

Logical Operators &, && - AND |, || - OR ~ - NOT

Logical Operators Evaluate the following as true or false for x=5:  x < 7 & 3 < x 2. ˜ (x / 2 > 1 & x < 0)  x ˜ = 5 & x + 2 > 6 | x > 5  x + x == 2 * x && ˜ x

Functions.m-file ◦ Function name same as file name Contains a function name, arguments, output, and “implementation” ◦ Contract ◦ Description ◦ Examples All variables in function are local ◦ They are not visible outside call!

Example Function %circleArea(number) -> number %Authors: James Atlas %CISC106 Lab Section 45 TA: Scott Ivanka %Description: % This function computes the area of a circle given the radius. %Examples: % circleArea(3) -> 28 % circleArea(5) -> 78 % circleArea(45) -> 6362 function output = circleArea(radius) output = pi * radius * radius;

Recursive Function Function that refers to itself Example: sum numbers 1 to n function out=sum(n) if n < 1 out = 0; else out = n + sum(n - 1);

Recursive Function Function that refers to itself Example: sum numbers 1 to n function out=sum(n) if n < 1 out = 0; else out = n + sum(n - 1);

Tracing Functions Non-recursive, call to function a() function out = a() out = b(); function out = b() out = c(); function out = c() out = 5;

Tracing Functions functionarglocal return value function out = a() out = b(); function out = b() out = c(); function out = c() out = 5;

Tracing Functions ab() functionarglocalreturn value function out = a() out = b(); function out = b() out = c(); function out = c() out = 5;

Tracing Functions ab() bc() functionarglocalreturn value function out = a() out = b(); function out = b() out = c(); function out = c() out = 5;

Tracing Functions ab() bc() c 5 functionarglocalreturn value function out = a() out = b(); function out = b() out = c(); function out = c() out = 5;

Tracing Functions ab() b5 5 c 5 functionarglocalreturn value function out = a() out = b(); function out = b() out = c(); function out = c() out = 5;

Tracing Functions a5 5 b5 5 c 5 functionarglocalreturn value function out = a() out = b(); function out = b() out = c(); function out = c() out = 5;

Tracing Functions a5 5 b5 5 c 5 functionarglocalreturn value function out = a() out = b(); function out = b() out = c(); function out = c() out = 5;

Tracing Recursion Recursive call to function sum(3) function out=sum(n) if n < 1 out = 0; else out = n + sum(n - 1);

Tracing Recursion sum(n) if n < 1 out = 0; else out = n + sum(n - 1); sumn=3sum(2) functionarglocalreturn value

Tracing Recursion sum(n) if n < 1 out = 0; else out = n + sum(n - 1); sumn=3sum(2) functionarglocalreturn value sumn=2sum(1)

Tracing Recursion sum(n) if n < 1 out = 0; else out = n + sum(n - 1); sumn=3sum(2) functionarglocalreturn value sumn=2sum(1) sumn=1sum(0)

Tracing Recursion sum(n) if n < 1 out = 0; else out = n + sum(n - 1); sumn=3sum(2) functionarglocalreturn value sumn=2sum(1) sumn=1sum(0) sumn=0 0

Tracing Recursion sum(n) if n < 1 out = 0; else out = n + sum(n - 1); sumn=3sum(2) functionarglocalreturn value sumn=2sum(1) sumn=10 1 sumn=0 0

Tracing Recursion sum(n) if n < 1 out = 0; else out = n + sum(n - 1); sumn=3sum(2) functionarglocalreturn value sumn=21 3 sumn=10 1 sumn=0 0

Tracing Recursion sum(n) if n < 1 out = 0; else out = n + sum(n - 1); sumn=33 6 functionarglocalreturn value sumn=21 3 sumn=10 1 sumn=0 0

Tracing Recursion sum(n) if n < 1 out = 0; else out = n + sum(n - 1); sumn=33 6 functionarglocalreturn value sumn=21 3 sumn=10 1 sumn=0 0

Arrays All variables in matlab are arrays An array of one element is called a scalar A one dimension array is called a vector x=3.14;  scalar a = [1,2,3,4,5];  vector

Arrays Interval notation x = 1:0.5:5 Now x is a vector of numbers: x = [1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]

Arrays (aka matrices) A = [1, 2; 3, 4; 5, 6] Creates a 3x2 matrix, 3 rows, 2 columns. semicolon creates a new row. A =

a = [ ] b = [1; 2; 3; 4] c = [1 2; 3] (error) d = [1 2; 3 4] f = d(1,2) g(4,5) = 7 a(3:end) a(1:2:end) d’ Array commands

For Loops Used when you know how many times code is to be executed. Syntax for = : : Variable is initially the start value At end of iteration variable changes by increment If value is not greater than end the loop runs again.

Example Problem total = 0; for i = 1:1:1000 loop starts at 1 total = total + i;loop increments by 1 end loop ends at 1000 disp(total);

A Loop Analogy (for) The runner executes a loop. If they know the distance they want to run For loop for lapCount = start : 1 : end runLap() end

A Loop Analogy (while) The runner executes a loop. If they don’t know the distance they want to run (run until tired) While loop tired = false; while(~tired) tired = runLap() end