160 likes | 239 Views
Arrays – the Basics. Arrays Scalar Vectors Matrices. 1. 1. An array. An array is a collection of data into one variable The array has a more precise name , depending on the dimension of the variable: A “scalar” A “vector” A “matrix”. The difference…. 2. 1 st . “A scalar ”.
E N D
Arrays – the Basics Arrays Scalar Vectors Matrices 1
1. An array • An array is a collection of data into one variable • The array has a more precise name, depending on the dimension of the variable: • A “scalar” • A “vector” • A “matrix” The difference… 2
1st . “A scalar” • A value, just one. • The dimension is 1 x 1. • Example: the number 7 is a scalar. age = 17; %creates a scalar variable weight = 145.32; %another scalar variable 3
2nd . “Vector” – math In 2D: 4
2nd . “Vector” – math In 2D: In 3D: The vector OP has initial point at the origin O(0,0,0) and terminal point at P(2,3,5). We can draw the vector OP as follows: Source: http://www.intmath.com/Vectors/1_Vector-concepts.php In 3D: 5
“Vector” – Matlab • A vector is only a collection of data • “all the temperatures readings during take-off” • “all the pressures recorded during Hurricane Katrina” • “an (x,y,z) coordinate” 6
“Vector” – Matlab • A vector is only a collection of data • “all the temperatures readings during take-off” • “all the pressures recorded during Hurricane Katrina” • “an (x,y,z) coordinate” • A vector can only be of two types: a column, or a row • For an array to be a vector, only ONE of this variable’s dimension is 1. A column vector (“m by 1”) A row vector (“1 by m”) 7
Vectors, end. • Vectors are usually thought of as “row vectors” or “column vector”, but there exists one more: The “empty vector” – a variable in MATLAB that contains no values. To make an empty vector, use the empty brackets: E = [];
Vectors, end. • Vectors are usually thought of as “row vectors” or “column vector”, but there exists one more: The “empty vector” – a variable in MATLAB that contains no values. To make an empty vector, use the empty brackets: E = []; • Why do this? • Create a variable, much like a container ready to accept values. • Erase the previous content of an array, without destroying the variable itself.
3rd . A “matrix” • Both dimensions are greater than 1. • Can be used to: • Represent mathematical matrices, or • Simply store information • First row: temperature of different points in a nozzle • Second row: pressure at those same points • Third row: density at those same points an “r by c” 10
3rd . A “matrix”, vocabulary • LEARN this NOW – everything depends on you referring to these correctly! 1 2 3 4 5 6 7 8 9 0 3 1 5 6 1 4 3 5 6 7 3 1 2 0 0 ROW!
3rd . A “matrix”, vocabulary • LEARN this NOW – everything depends on you referring to these correctly! 1 2 3 4 5 6 7 8 9 0 3 1 5 6 1 4 3 5 6 7 3 1 2 0 0 COLUMN!
Wrapping Up • Vocabulary: array, scalar, vector, matrix, row, column 13
Wrapping Up • Vocabulary: array, scalar, vector, matrix, row, column • An array allows a LOT of data to be stored into ONE variable. • Useful since when there is a LOT of data, having a separate variable for each number would be insane to keep track of! 14
Wrapping Up • Vocabulary: array, scalar, vector, matrix, row, column • An array allows a LOT of data to be stored into ONE variable. • Useful since when there is a LOT of data, having a separate variable for each number would be insane to keep track of! • There are different types of arrays: scalars, vectors and matrices. • Each specific name is linked to the dimension of the variable. 15
Wrapping Up • Vocabulary: array, scalar, vector, matrix, row, column • An array allows a LOT of data to be stored into ONE variable. • Useful since when there is a LOT of data, having a separate variable for each number would be insane to keep track of! • There are different types of arrays: scalars, vectors and matrices. • Each specific name is linked to the dimension of the variable. • Reset any array to empty using a set of empty square brackets. 16