EGR 106 – Week 3 – More on Arrays Brief review of last week Additional ideas: – Special arrays – Changing an array – Some array operators – Character arrays.

Slides:



Advertisements
Similar presentations
Lecture 4.
Advertisements

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.
Maths for Computer Graphics
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Part 3 Chapter 8 Linear Algebraic Equations and Matrices PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Part 1 Chapter 2 MATLAB Fundamentals
MATLAB Fundamentals.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
ENGR-25_Arrays-2.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
MATLAB Basics With a brief review of linear algebra by Lanyi Xu modified by D.G.E. Robertson.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Matlab Chapter 2: Array and Matrix Operations. What is a vector? In Matlab, it is a single row (horizontal) or column (vertical) of numbers or characters.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
MATLAB Lecture Two Tuesday 5 July Chapter 3.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
Chapter 2 Creating Arrays Legend: MATLAB command or syntax : Blue MATLAB command OUTPUT : LIGHT BLUE.
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Array Creation ENGR 1181 MATLAB 2. Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data.
Basic Matrix Operations Matrix – a rectangular array of numbers, variables, and both Order (dimensions) – describes the number of rows and columns in a.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
LEARNING OUTCOMES At the end of this topic, student should be able to :  D efination of matrix  Identify the different types of matrices such as rectangular,
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
Project Teams Project on Diffusion will be a TEAM project. 34 Students in class so 6 teams of 5 and one Team of 4. Determine members of team and a team.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
An Introduction to Programming in Matlab Emily Blumenthal
ENG College of Engineering Engineering Education Innovation Center 1 Arrays in MATLAB Topics Covered: 1.Creating arrays of numbers vectors matrices.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
MTH108 Business Math I Lecture 20.
ECE 1304 Introduction to Electrical and Computer Engineering
Linear Algebraic Equations and Matrices
Manipulating MATLAB Matrices Chapter 4
Numeric, Cell and Structural Arrays One of the strenghts of MATLAB is the capabilty to handle collection of numbers called ARRAYS. MATLAB refers to scalars,
Chapter 3 Arrays and Vectors
EGR 115 Introduction to Computing for Engineers
Introduction to Programming for Mechanical Engineers (ME 319)
Warm-up a. Solve for k: 13 −5
Part 1 Chapter 2 MATLAB Fundamentals
Vectors and Matrices I.
Introduction to MATLAB [Vectors and Matrices] Lab 2
Part 1 Chapter 2 MATLAB Fundamentals
Matlab Training Session 2: Matrix Operations and Relational Operators
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
EECS Introduction to Computing for the Physical Sciences
Presentation transcript:

EGR 106 – Week 3 – More on Arrays Brief review of last week Additional ideas: – Special arrays – Changing an array – Some array operators – Character arrays Element by element math operations Textbook – rest of chapter 2, 3.1, 3.4, 3.5

Review of Last Week The fundamental data unit in Matlab – Rectangular collection of data – All variables are considered to be arrays Data values organized into rows and columns

Size of an array Construction: – Brute force using brackets – Concatenation of other arrays – L/R and U/D – The colon operator Addressing: – Individual elements – Subarrays

Some new tricks: – end specifies the last row or column – a colon ( : ) specifies all of a row or column yield(2,:) yield(end,1) – use a single index for row and column vectors bob = [ ] bob(4)

Special Arrays Special predefined arrays: – all zeroszeros(R,C)zeros(N) – all onesones(R,C)ones(N) – zeros with ones on the diagonal eye(R,C)eye(N) – random numbers (within [ 0 1 ]) rand(R,C)rand(N) Square versions

random on [ 0, 1 ]

Linspace – like the colon operator, but definitely gets the last number on the list linspace ( start, last, number of values) – examples: linspace(0,10,6) [ ] linspace(0,1,4)[ ] – default for number is 100 linspace(0,10) [ … 10 ] Note increment for 100 points, 99 intervals

Changing an Array Recall reading an array value:

To change a single value in an array – Use addressing on the left hand side of =

Can also be used to change a sub-array Note – array on the right needs to be of the correct size !!!

Wrong number of elements for the assignment Wrong dimensions for assignment Watch for addressing errors:

Other useful methods that do work: Assigning values with too large an index just grows the array

Scalars work for sub- array replacement – they just scale up to the right size

Replacing with a null matrix is the same as deleting – but it only works for entire rows or columns

Some Array Operators Transpose (single quote symbol ' ) – switches rows and columns

Size – the number of rows and columns Length – the larger of these two Array answer Scalar answer

Diag – matrix vector operator for diagonal elements

Reshape – resize fixed set of elements Note – the set of elements is exactly the same Note column- wise approach to re-ordering the values

Character Arrays Rows of the array are strings of alphanumeric characters, one array entry per character Enter using a single quotation mark ( ' ) at each end of the string

– For multi-row alphanumeric arrays, each row must have the same number of characters name = [ 'Marty' ; 'James' ; 'Bob ' ] – Use 2 quotation marks in a row to get 1 'Mary''s' Mary's (a 1 by 6 array) – Also, there are some built-in arrays y = date y = 05-Jan-2004 (a 1 by 11 array) Note – need 2 spaces

Element by Element Math Operations For arrays of identical sizes, addition is defined term by term: – the command F = A + B means F(r,c) = A(r,c) + B(r,c) – for all row and column pairs r,c “element-by-element” addition

For example: Notes: – Arrays must be of identical sizes – One can be a scalar (it is “sized up”) – Subtraction is identical

The other basic math operations work element by element using the dot notation (with A,B the same sizes): – multiplication F = A.* B  F(r,c) = A(r,c) * B(r,c) – division F = A./ B  F(r,c) = A(r,c) / B(r,c) – exponentiation: F = A.^ B  F(r,c) = A(r,c) ^ B(r,c) note periods!

For example:

One could be scalar: a = [ ] b = 2

Built-in functions also work element-by- element: – log and exp – trigonometric – etc.