{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture_04_E7_L4_2D_arrays_F07

# Lecture_04_E7_L4_2D_arrays_F07 - 1 E7 INTRODUCTION TO...

This preview shows pages 1–13. Sign up to view the full content.

E7 L3 1 E7: INTRODUCTION TO COMPUTER E7: INTRODUCTION TO COMPUTER PROGRAMMING FOR SCIENTISTS AND PROGRAMMING FOR SCIENTISTS AND ENGINEERS ENGINEERS Lecture Outline 1. Two-dimensional arrays 2. Polynomials Copyright 2007, Horowitz, Packard. This work is licensed under the Creative Commons Attribution-Share Alike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L3 2 Introduction to arrays Introduction to arrays Examples: 2-dimensional arrays (2 rows, 3 columns) (3 rows, 3 columns) 1.2 3.2 1.0 3.1 92 0.0 d - = 1 4 6 7 2 5 8 4 3 e =
E7 L4 3 2-dimensional arrays 2-dimensional arrays A rectangular arrangement of numbers is called an array. 2 1 2 3 4 5 - Example: 3-by-2 array. (3 rows, and 2 columns) (3,1) element (3 rd row, and 1 st column) Matlab 2-D convention: ( Row , Column)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L4 4 Creating arrays – manual construction Creating arrays – manual construction Example 1: >> A = [ 2 1 ; -2 3 ; 4 5 ] A = 2 1 -2 3 4 5 2 1 2 3 4 5 A = - The semicolon is used to demark rows
E7 L4 5 Creating arrays – manual construction Creating arrays – manual construction Example 1: carriage return <CR> is also used to demark rows >>A = [ 2 1 -2 3 4 5 ] A = 2 1 -2 3 4 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example 1: >>A = [[ 2 ; -2 ; 4 ] , [ 1 ; 3 ; 5 ] ] A = 2 1 -2 3 4 5 E7 L4 6 Creating arrays – manual construction Creating arrays – manual construction first column second column
Example 1: >>A = [[ 2 ; -2 ; 4 ] [ 1 ; 3 ; 5 ] ] A = 2 1 -2 3 4 5 E7 L4 7 Creating arrays – manual construction Creating arrays – manual construction first column second column comma is not needed

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example 1: >> A = [[ 2;-2 ;4 ] ... [ 1 ; 3 ; 5 ] ] A = 2 1 -2 3 4 5 E7 L4 8 Creating arrays – manual construction Creating arrays – manual construction “...” - allows a new line without a <CR>
Example 1: >>A = [[ 2;-2 ;4 ] [ 1 ; 3 ; 5 ] ] A = 2 -2 4 1 3 5 E7 L4 9 Creating arrays – manual construction Creating arrays – manual construction <CR> means a new row

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
zeros, ones and rand commands zeros, ones and rand commands E7 L3 10 >> A = ones(2,3) A = 1 1 1 1 1 1 >> B = zeros(2,2) B = 0 0 0 0 Matlab 2-D convention: >> r = 3*ones(1,5) r = 3 3 3 3 3 (rows, columns)
Array concatenation Array concatenation E7 L3 11 >> A = ones(2,3) A = 1 1 1 1 1 1 >> B = zeros(2,2) B = 0 0 0 0 >> C = [ A B ] C = 1 1 1 0 0 1 1 1 0 0

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Array concatenation Array concatenation E7 L3 12 >> C = [ A B ] C = 1 1 1 0 0 1 1 1 0 0 C is the array formed by stacking A “next to” B Once constructed, C does not “know” that it came from two arrays.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern