Array_Processing

Array_Processing - Array Processing How would we start to...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Array Processing How would we start to arrange the following values in ascending order? 95 24 61 49 89 76 46 30 82 45 These might represent a set of grades or some other numbers that have something in common. Most programming languages have methods for defining and manipulating arrays of values. MATLAB was designed to work easily with one dimensional and multidimensional arrays Defining a vector (Row vector) • MATLAB is a tool for doing computations with vectors & matrices • Row Vectors: » v1 = [2 3, 3] v1 = 2 3 3 » length (v1) ans = 3 Name of vector You can use either a space or comma to separate the elements in vector definition Square bracket Reports the number of elements in a vector Defining a vector (Column vector) • Similar you can also define a column vector » c1 = [1;3;2] c1 = 1 3 2 Use semicolon to change rows Square bracket Vectors Vectors are one dimensional arrays of items. = n x x x x x 3 2 1 x is a column vector: [ ] m y y y y y 3 2 1 = y is a row vector: The individual entries in a vector are called elements. Transpose Operator It waste a lot of space to write large column vectors another way to write x is: [ ] T 3 2 1 n x x x x x = The T is the transpose operator. It changes the rows of a vector (or matrix) into columns and vice-versa. The Matlab colon operator can be used to create vectors whose elements form a series: y = start : stop z = start : increment : stop [ ] 6 5 4 3 2 6 : 2 = = y [ ] 6 . 5 5 4 . 4 8 . 3 2 . 3 6 . 2 2 6 : 6 . : 2 = = z Creating Vectors with Constant Spacing and Known Element Count vname = linspace( xi, xf, n ) xi is first element xf is last element n is number of elements in vector omitted n gives 100 elements >> z = linspace( 1, 5, 9 ) z = 1 1.5 2 2.5 3 3.5 4 4.5 5 Vector Operations Assume two column vectors x and y: = n x x x x x 3 2 1 = n y y y y y 3 2 1 Summation ± ± ± = ± n n i i y x y x y x y x 1 1 • Summation is done element-by-element (a Matlab term) • The vectors must be of the same type and length Scalar Addition + + + = + a x a x a x a x n i 1 The scalar is added to each element in the vector. Scalar Product...
View Full Document

This note was uploaded on 10/28/2011 for the course CHE 210 taught by Professor Swinnea during the Fall '08 term at University of Texas.

Page1 / 40

Array_Processing - Array Processing How would we start to...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online