General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/30/2009.

Slides:



Advertisements
Similar presentations
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Advertisements

General Computer Science for Engineers CISC 106 Midterm 2 Review James Atlas Computer and Information Sciences 11/06/2009.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
Section 2 Appendix Tensor Notation for BP 1. In section 2, BP was introduced with a notation which defined messages and beliefs as functions. This Appendix.
General Computer Science for Engineers CISC 106 Lecture 02 James Atlas Computer and Information Sciences 6/10/2009.
CIS 101: Computer Programming and Problem Solving Lecture 6 Usman Roshan Department of Computer Science NJIT.
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
General Computer Science for Engineers CISC 106 Lecture 22 Dr. John Cavazos Computer and Information Sciences 04/13/2009.
Lab2 (Signal & System) Instructor: Anan Osothsilp Date: 07 Feb 07.
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/23/2009.
General Computer Science for Engineers CISC 106 Lecture 24 Christopher Thorpe Computer and Information Sciences 04/17/2009.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
General Computer Science for Engineers CISC 106 Lecture 07 Dr. John Cavazos Computer and Information Sciences 2/25/2009.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/18/2009.
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 08
General Computer Science for Engineers CISC 106 Lecture 12 Roger Craig Computer and Information Sciences 3/11/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 James Atlas Computer and Information Sciences 11/13/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 James Atlas Computer and Information Sciences 11/16/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 23 Dr. John Cavazos Computer and Information Sciences 4/15/2009.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/26/2009.
MATLAB Cell Arrays Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
General Computer Science for Engineers CISC 106 Lecture 08 James Atlas Computer and Information Sciences 9/21/2009.
General Computer Science for Engineers CISC 106 Lecture 18 Dr. John Cavazos Computer and Information Sciences 3/27/2009.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/21/2009.
General Computer Science for Engineers CISC 106 Lecture 06 Roger Craig Computer and Information Sciences 2/23/2009.
Matrix Mathematics in MATLAB and Excel
BEGINNING MULTIPLICATION BASIC FACTS Multiplication is REPEATED ADDITION. It is a shortcut to skip counting. The first number in the problem tells.
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 06/29/2009.
General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009.
Selection Programming EE 100. Outline introduction Relational and Logical Operators Flow Control Loops Update Processes.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
For many calculators if you input "the square root of -1", you will get out "domain error" Input Output This was done with a TI-30XS calculator.
BEGINNING MULTIPLICATION BASIC FACTS Multiplication is REPEATED ADDITION. It is a shortcut to skip counting. The first number in the problem tells.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
1 1 Completing the Square This is an x.Show me x 2. x x 2 Show me x 2 + 6x.
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.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 2 Wednesday 15 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Basics Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
General Computer Science for Engineers CISC 106 Lecture 13 - Midterm Review James Atlas Computer and Information Sciences 10/02/2009.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
General Computer Science for Engineers CISC 106 Lecture 15 Dr. John Cavazos Computer and Information Sciences 03/16/2009.
Engineering Computing I Chapter 5 Pointers and Arrays.
General Computer Science for Engineers CISC 106 Lecture 06 James Atlas Computer and Information Sciences 06/24/2009.
General Computer Science for Engineers CISC 106 Lecture 14 James Atlas Computer and Information Sciences 08/10/2009.
Improving Matlab Performance CS1114
13.1 Sequences. Definition of a Sequence 2, 5, 8, 11, 14, …, 3n-1, … A sequence is a list. A sequence is a function whose domain is the set of natural.
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
State Space Models The state space model represents a physical system as n first order differential equations. This form is better suited for computer.
General Computer Science for Engineers CISC 106 Lecture 27 Dr. John Cavazos Computer and Information Sciences 04/27/2009.
The Accumulator Pattern Motivating Example: Suppose that you want to add up (“accumulate”) 1 2 plus 2 2 plus 3 2 plus … plus You could use: total.
General Computer Science for Engineers CISC 106 Lecture 09 Dr. John Cavazos Computer and Information Sciences 03/04/2009.
General Computer Science for Engineers CISC 106 Lecture 10 James Atlas Computer and Information Sciences 07/15/2009.
Chapter2 Creating Arrays
General Computer Science for Engineers CISC 106 Lecture 15
General Computer Science for Engineers CISC 106 Lecture 11
ME 123 Computer Applications I Lecture 4: Vectors and Matrices 3/14/03
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/30/2009

Lecture Overview MATLAB array initialization ◦ “growing” arrays Vectorization ◦ mask arrays MATLAB functions ◦ find ◦ any, all ◦ randi

MATLAB Array Initialization y = []; for i = 1:10 y(i) = i; end; How does this work?

MATLAB Array Initialization y = []; for i = 1:10 y(i) = i; end; This is an example of “growing” an array

MATLAB Array Initialization y = zeros(1,10); for i = 1:10 y(i) = i; end; Initializes the array first

Vectorization What is vectorization? ◦ Functions that can be performed on the entire array instead of just one element in an array. Advantages of vectorization ◦ Fast and compact. Disadvantages of vectorization ◦ Hard to look at what is going on ‘inside’

The ‘loopy’ way ◦ function output = square(input) n = length(input); for i = 1:n output(i) = input(i)^2; end The ‘vector’ way ◦ Output = input.^2; Given an array of arbitrary size: Square each element in the array and put the result into a new array. Vectorization

The ‘loopy’ way function count = num_less_than(input, value) n = length(input); count = 0; for i = 1:n if (input(i) < value) count = count + 1; end The ‘vector’ way vector_less = (input < value); count = sum(vector_less); Given an array of arbitrary size: Tell me how many elements of the given array are less than a given value. Vectorization

The ‘loopy’ way function count = num_less_than(input, value) n = length(input); count = 0; for i = 1:n if (input(i) < value) count = count + 1; end The ‘vector’ way vector_less = (input < value); count = sum(vector_less); Given an array of arbitrary size: Tell me how many elements of the given array are less than a given value. Vectorization How does the vector way work?

Vectorization vector_less = (input < value); count = sum(vector_less); Let’s open MATLAB to see

Vectorization Additional examples ◦ x = [ ]; ◦ x < 3 ◦ x(x < 3) ◦ x(x 3) x < 3 produces a mask

Masking Masking selects only certain elements of an array to perform an operation Masking uses an array of only 0’s and 1’s that is the same size as the argument ◦ y = x < 3 ◦ whos y ◦ y is a mask of x that selects only the elements that are less than 3

Masking x = [ ]; y = x < 3 x(y) = x(y).* 2;

MATLAB functions - find find ◦ locates all nonzero elements of array z = [ ]; find(z) ◦ [1 2 6]

MATLAB functions - any/all x = [ ]; any(x < 3) any(x < 0) all(x > 1) all(x > 0)

MATLAB functions - randi rand() randi(100)