General Computer Science for Engineers CISC 106 Lecture 24 Christopher Thorpe Computer and Information Sciences 04/17/2009.

Slides:



Advertisements
Similar presentations
Introduction to MATLAB The language of Technical Computing.
Advertisements

1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
General Computer Science for Engineers CISC 106 Midterm 2 Review James Atlas Computer and Information Sciences 11/06/2009.
CMPS 1371 Introduction to Computing for Engineers STRUCTURE ARRAYS.
Implementing the Probability Matrix Technique for Positron Emission Tomography By: Chris Markson Student Adviser: Dr. Kaufman.
Maths for Computer Graphics
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/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.
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 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.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
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.
CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.
Lecture 7 Sept 19, 11 Goals: two-dimensional arrays (continued) matrix operations circuit analysis using Matlab image processing – simple examples Chapter.
Lecture#6: segmentation Anat Levin Introduction to Computer Vision Class Fall 2009 Department of Computer Science and App math, Weizmann Institute of Science.
Finding Red Pixels – Part 1 Prof. Noah Snavely CS1114
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 11/13/2009.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/30/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 Lecture 26 Dr. John Cavazos Computer and Information Sciences 04/24/2009.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/26/2009.
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 Lecture 06 Roger Craig Computer and Information Sciences 2/23/2009.
3D Graphics Goal: To produce 2D images of a mathematically described 3D environment Issues: –Describing the environment: Modeling (mostly later) –Computing.
Lecture 7: Matrix-Vector Product; Matrix of a Linear Transformation; Matrix-Matrix Product Sections 2.1, 2.2.1,
CE 311 K - Introduction to Computer Methods Daene C. McKinney
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 06/29/2009.
Creating With Code.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009.
Lecture 28: Mathematical Insight and Engineering.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
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.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Today’s lecture 2-Dimensional indexing Color Format Thread Synchronization within for- loops Shared Memory Tiling Review example programs Using Printf.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
1 Regions and Binary Images Hao Jiang Computer Science Department Sept. 25, 2014.
Matrices Matrices A matrix (say MAY-trix) is a rectan- gular array of objects (usually numbers). An m  n (“m by n”) matrix has exactly m horizontal.
2009/9 1 Matrices(§3.8)  A matrix is a rectangular array of objects (usually numbers).  An m  n (“m by n”) matrix has exactly m horizontal rows, and.
Copyright © Curt Hill Multiple Dimension Arrays Extending Java Arrays.
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
Christopher Mitchell The Cooper Union Fluorescent Microscopy, Eigenobjects, and the Cellular Density Project Christopher Mitchell The Cooper Union Stevens.
Module #9: Matrices Rosen 5 th ed., §2.7 Now we are moving on to matrices, section 7.
Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.
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 MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
CS/EE 217 GPU Architecture and Parallel Programming Midterm Review
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
General Computer Science for Engineers CISC 106 Lecture 15 Dr. John Cavazos Computer and Information Sciences 03/16/2009.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
General Computer Science for Engineers CISC 106 Lecture 14 James Atlas Computer and Information Sciences 08/10/2009.
Improving Matlab Performance CS1114
1 ECE 221 Electric Circuit Analysis I Chapter 6 Cramer’s Rule Herbert G. Mayer, PSU Status 11/14/2014 For use at Changchun University of Technology CCUT.
1.8 Multidimensional Arrays academy.zariba.com 1.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Matrix Algebra Definitions Operations Matrix algebra is a means of making calculations upon arrays of numbers (or data). Most data sets are matrix-type.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
ENG College of Engineering Engineering Education Innovation Center 1 Arrays in MATLAB Topics Covered: 1.Creating arrays of numbers vectors matrices.
General Computer Science for Engineers CISC 106 Lecture 10 James Atlas Computer and Information Sciences 07/15/2009.
General Computer Science for Engineers CISC 106 Lecture 11
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 24 Christopher Thorpe Computer and Information Sciences 04/17/2009

Lecture Overview Structs ( ) Vectorization Matrix Tricks

Given: Name: Chris Credits: 27 Graduation: 12/15/2011 Name: Sola Credits: 18 Graduation: 05/17/2011 Name: Roger Credits: 55 Graduation: 06/10/2009 Name: Tom Credits: 15 Graduation: 05/22/2012

Given: We can implement it with arrays like this: Name Credits Grad Name: Chris Credits: 27 Graduation: 12/15/2011 Name: Sola Credits: 18 Graduation: 05/17/2011 Name: Roger Credits: 55 Graduation: 06/10/2009 Name: Tom Credits: 15 Graduation: 05/22/ Chris12/15/ Sola05/17/ Roger06/10/ Tom05/22/2012

Given: OR we can do it like this an array with structs:.d Name: Chris Credits: 27 Graduation: 12/15/2011 Name: Sola Credits: 18 Graduation: 05/17/2011 Name: Roger Credits: 55 Graduation: 06/10/2009 Name: Tom Credits: 15 Graduation: 05/22/2012 Students (1). Name: Chris Students (1).Credits: 27 Students (1). Graduation: 12/15/2011 Students (2).Name: Sola Students (2).Credits: 18 Students (2).Graduation: 05/17/2011 Students (3). Name: Roger Students (3). Credits: 55 Students (3). Graduation: 06/10/2009 Students (4). Name: Tom Students (4). Credits: 15 Students (4). Graduation: 05/22/2012

Students = struct{‘name’, {‘Chris’, ‘Sola’,’Roger’, Tom’}, ‘credits’, {27, 18, 55, 15}, ‘graduation’, { ‘12/15/2011’,’ 05/17/2011’,’ 06/10/2009’,’05/22/2012’} record1.name = 'Me'; record2.name = 'Not Me'; record1.credits = 27; record2.credits = 30; record1.age = 10; record2.age = 14; record1 record2 record_array = [record1, record2];

What is vectorization? ◦ Functions that can be performed on the entire array instead of just one element in an array. ◦ Needed because MATLAB is an interpreter not a compiler AND because speed is important. Advantages of vectorization ◦ Fast and compact. Disadvantages of vectorization ◦ Hard to look at what is going on ‘inside’ ◦ Application to your current code is not always apparent

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.

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.

The ‘loopy’ way function output = num_less_than(input, value1, value2) [rows, cols] = size(input); for i = 1:rows for j = 1:cols if(input(i, j) < value1) output(i, j) = value2; else output(i, j) = input(i, j); end end….. The ‘vector’ way vector_less = (input < value); vector_less = ~vector_less; temp = vector_less.*input; vector_less = vector_less.*5; output = vector_less+temp; Given a grayscale image of arbitrary size: Make all pixels less than value1 equal to value2

Sometimes you want to know how many elements are in a matrix. ◦ Useful for normalization problems. ◦ Num_elements = numel(input); Sometimes you want to change the shape of a matrix. ◦ For matrix multiplication ◦ For simple output ◦ New_matrix = reshape(matrix, m, n);

Sometimes your matrix is ‘bloated’ (seems larger than it really is) ◦ Makes some mathematical operations impossible. ◦ Makes accessing some dimensions tedious. ◦ New_matrix = squeeze(matrix); Sometimes you need to change the order in which some dimensions appear. ◦ For matrix multiplication ◦ For simple output ◦ New_matrix = shiftdim(matrix, n);