This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: AN INTRODUCTION TO MATLAB MELVIN LEOK MATLAB is an interactive environment for numerically manipulating arrays and matrices, as well as providing tools for visualizing data. It is particularly appropriate for implementing simple numerical algorithms as it provides the necessary data structures, matrix operations, and visualization tools, thereby allowing one to concentrate on the algorithmic structure of the numerical methods we study. Scalars, Arrays, and Matrices Scalars: To assign a scalar value to a variable, >> x = 0.2 By default, MATLAB will echo the value you entered, x = 0.2000 unless you suppress output by adding a semi- colon to the end of your command, >> x = 0.2; Row vectors: To enter a row vector, >> y = [1 2 3] where each term in row is separated by either a space or a comma. Column vectors: To enter a column vector, >> y = [1;2;3] Notice that the rows are separated by semi- colons. Alternatively, we can take the matrix transpose of a row vector, >> y = [1 2 3] where the denotes the transpose operation. Matrices: As is the case for row and column vec- tors, we separate terms in each row by a space, and we separate the rows by semicolons, >> A = [1 2 3;4 5 6; 7 8 9] Special Matrices: It is often convenient to con- struct the following special vectors and matrices, Equally spaced elements in a vector: To create a vector starting at and ending at 2 with intervals 0.5 , we enter, >> v = 0:0.5:2 v = 0 0.5000 1.0000 1.5000 2.0000 We could also have constructed a linear space that starts at and ends at 2 , with 5 evenly spaced entries, >> v = linspace(0,2,5); Matrix of zeros: >> Z = zeros(3,5); Matrix of ones: >> X = ones(3,5); Identity matrix: >> I = eye(3); Diagonal matrices: If you wish to create a...
View Full Document