General Computer Science for Engineers CISC 106 Lecture 11

Slides:



Advertisements
Similar presentations
Introduction to arrays
Advertisements

Maths for Computer Graphics
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
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 04 Roger Craig Computer and Information Sciences 9/11/2009.
General Computer Science for Engineers CISC 106 Lecture 20 Dr. John Cavazos Computer and Information Sciences 04/08/2009.
General Computer Science for Engineers CISC 106 Final Exam Review Dr. John Cavazos Computer and Information Sciences 05/18/2009.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
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 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.
Orthogonal Sets (12/2/05) Recall that “orthogonal” matches the geometric idea of “perpendicular”. Definition. A set of vectors u 1,u 2,…,u p in R n is.
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.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 06/29/2009.
Traversing an array 1.Definition 2.Use the for loop 3.Some new functions 4.Use the while loop 1.
13.1 Matrices and Their Sums
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.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
How to Multiply Two Matrices. Steps for Matrix Multiplication 1.Determine whether the matrices are compatible. 2.Determine the dimensions of the product.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
General Computer Science for Engineers CISC 106 Lecture 13 - Midterm Review James Atlas Computer and Information Sciences 10/02/2009.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
General Computer Science for Engineers CISC 106 Lecture 15 Dr. John Cavazos Computer and Information Sciences 03/16/2009.
What is Matrix Multiplication? Matrix multiplication is the process of multiplying two matrices together to get another matrix. It differs from scalar.
Multidimensional Arrays Computer and Programming.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
13.4 Product of Two Matrices
Linear Algebra review (optional)
Two-Dimensional Arrays
Two Dimensional Arrays
Introduction to Matrices
EGR 115 Introduction to Computing for Engineers
Chapter 4 MATLAB Programming
Multiplying Matrices.
WarmUp 2-3 on your calculator or on paper..
Engineering Problem Solving with C++, Etter/Ingber
Introduction to Matrices
EKT150 : Computer Programming
Vectors and Matrices I.
CSCI N207 Data Analysis Using Spreadsheet
Chapter2 Creating Arrays
The Matrix A b a d e a a a a a a a A b a d e a a a a a a a
2.2 Introduction to Matrices
Beginning C for Engineers
Unit 1 MATRICES Dr. Shildneck Fall, 2015.
Bingo Example: Design (Print Card Algorithm)
Multidimensional array
Multidimensional Arrays
Matrices.
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.
Multiplying Matrices.
Dr Tripty Singh Arrays.
Lets Play with arrays Singh Tripty
Multi-Dimensional Arrays
3.6 Multiply Matrices.
Linear Algebra review (optional)
EECS Introduction to Computing for the Physical Sciences
Matrices.
Matrix A matrix is a rectangular arrangement of numbers in rows and columns Each number in a matrix is called an Element. The dimensions of a matrix are.
Arrays in MatLab Arrays can have any number dimensions
Dale Roberts, Lecturer IUPUI
Working with Arrays in MATLAB
General Computer Science for Engineers CISC 106 Lecture 15
Announcements.
Announcements Exam 2 Next Week!! Final Exam :
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 11 Roger Craig Computer and Information Sciences 3/09/2009

Lecture Overview Lab (due Monday, tonight, at 11:55pm) / Midterm Review (3/17) Vectors, looping through Matrices, looping through

Vectors Vector = one dimensional array Since it is one dimensional, either m or n is equal to one 1 x n (one row). This is also called a “row vector” m x 1 (one column). This is called a “column vector” Can get length of the vector with the length(x) function length(vector) returns the length of the vector

Looping through a vector The following function loops through the inputVector and returns the number of 8s in it. (Note: this code can be found at http://www.udel.edu/CIS/106/cavazos/09S/examples/ ) function output = count8sVector( inputVector) %count number of 8s in a one dimensional array (i.e. a vector) numberOfEights = 0; %set number of observed 8s to zero lengthOfInputVector = length(inputVector); %get length of the vector for k = 1:lengthOfInputVector %for k equals 1 to length of vector if (inputVector(k) == 8) %if the kth position of the vector equals 8... numberOfEights = numberOfEights + 1; %increment the number of observed 8s fprintf('k is %d ', k); %print out the position of this observed 8 end %end the IF end %end of FOR loop output = numberOfEights; %return the number of observed 8s end

Matrices Matrix = two dimensional array m x n , where m is number of rows and n is number of columns Can get size of the matrix with the size(x) function size(inputMatrix) returns a 1x2 matrix that contains the number of rows and number of columns of the inputMatrix

Looping through a matrix (Note: this code can be found, much more nicely formatted, at http://www.udel.edu/CIS/106/cavazos/09S/examples/ ) This function loops through both dimensions of the inputMatrix and counts the number of 8s in it. function output = count8sMatrix( inputMatrix) %count number of 8s in a two dimensional array (i.e. a matrix) numberOfEights = 0; %set number of observed 8s to zero lengths = size(inputMatrix); %get m by n size of the matrix (m rows, n columns). And it these two dimensions are stored %in a 1 by 2 array called lengths fprintf('size of the matrix m by n is ') %print out... disp(lengths) %the dimensions of the matrix for m = 1:lengths(1) %for m equals 1 to "whatever is in the first index of lengths" for n = 1:lengths(2) %for n equals 1 to "whatever is in the second index of lengths" if (inputMatrix(m,n) == 8) %if the mth row and the nth column in the matrix is an eight, then... numberOfEights = numberOfEights + 1; % ...increment the number of observed eights end end %end of FOR loop for the columns end %end of FOR loop for the rows output = numberOfEights; %output the number of observed eights