Xem mẫu

Attia, John Okyere. “Matlab Fundamentals.” Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 © 1999 by CRC PRESS LLC CHAPTER ONE MATLAB FUNDAMENTALS MATLAB is a numeric computation software for engineering and scientific calculations. The name MATLAB stands for MATRIX LABORATORY. MATLAB is primarily a tool for matrix computations. It was developed by John Little and Cleve Moler of MathWorks, Inc. MATLAB was originally written to provide easy access to the matrix computation software packages LINPACK and EISPACK. MATLAB is a high-level language whose basic data type is a matrix that does not require dimensioning. There is no compilation and linking as is done in high-level languages, such as C or FORTRAN. Computer solutions in MATLAB seem to be much quicker than those of a high-level language such as C or FORTRAN. All computations are performed in complex-valued dou-ble precision arithmetic to guarantee high accuracy. MATLAB has a rich set of plotting capabilities. The graphics are integrated in MATLAB. Since MATLAB is also a programming environment, a user can extend the functional capabilities of MATLAB by writing new modules. MATLAB has a large collection of toolboxes in a variety of domains. Some examples of MATLAB toolboxes are control system, signal processing, neural network, image processing, and system identification. The toolboxes consist of functions that can be used to perform computations in a specific domain. 1.1 MATLAB BASIC OPERATIONS When MATLAB is invoked, the command window will display the prompt >>. MATLAB is then ready for entering data or executing commands. To quit MATLAB, type the command exit or quit MATLAB has on-line help. To see the list of MATLAB’s help facility, type help The help command followed by a function name is used to obtain informa-tion on a specific MATLAB function. For example, to obtain information on the use of fast Fourier transform function, fft, one can type the command © 1999 CRC Press LLC help fft The basic data object in MATLAB is a rectangular numerical matrix with real or complex elements. Scalars are thought of as a 1-by-1 matrix. Vectors are considered as matrices with a row or column. MATLAB has no dimension statement or type declarations. Storage of data and variables is allocated automatically once the data and variables are used. MATLAB statements are normally of the form: variable = expression Expressions typed by the user are interpreted and immediately evaluated by the MATLAB system. If a MATLAB statement ends with a semicolon, MATLAB evaluates the statement but suppresses the display of the results. MATLAB is also capable of executing a number of commands that are stored in a file. This will be discussed in Section 1.6. A matrix 1 2 3 A = 2 3 4 3 4 5 may be entered as follows: A = [1 2 3; 2 3 4; 3 4 5]; Note that the matrix entries must be surrounded by brackets [ ] with row elements separated by blanks or by commas. The end of each row, with the exception of the last row, is indicated by a semicolon. A matrix A can also be entered across three input lines as A = [ 1 2 3 2 3 4 3 4 5]; In this case, the carriage returns replace the semicolons. A row vector B with four elements B = [ 6 9 12 15 18 ] can be entered in MATLAB as © 1999 CRC Press LLC B = [6 9 12 15 18]; or B = [6 , 9,12,15,18] For readability, it is better to use spaces rather than commas between the ele-ments. The row vector B can be turned into a column vector by transposition, which is obtained by typing C = B’ The above results in C = 6 9 12 15 18 Other ways of entering the column vector C are C = [6 9 12 15 18] or C = [6; 9; 12; 15; 18] MATLAB is case sensitive in naming variables, commands and functions. Thus b and B are not the same variable. If you do not want MATLAB to be case sensitive, you can use the command casesen off To obtain the size of a specific variable, type size ( ). For example, to find the size of matrix A, you can execute the following command: size(A) © 1999 CRC Press LLC The result will be a row vector with two entries. The first is the number of rows in A, the second the number of columns in A. To find the list of variables that have been used in a MATLAB session, type the command whos There will be a display of variable names and dimensions. Table 1.1 shows the display of the variables that have been used so far in this book: Table 1.1 Display of an output of whos command Name Size A 3 by 3 B 1 by 5 C 5 by 1 ans 1 by 2 Elements Byte 9 72 5 40 5 40 2 16 Density Full Full Full Full Complex No No No No The grand total is 21 elements using 168 bytes. Table 1.2 shows additional MATLAB commands to get one started on MATLAB. Detailed descriptions and usages of the commands can be obtained from the MATLAB help facility or from MATLAB manuals. Table 1.2 Some Basic MATLAB Commands Command % demo length clear clc clg diary Description Comments. Everything appearing after % com-mand is not executed. Access on-line demo programs Length of a matrix Clears the variables or functions from workspace Clears the command window during a work session Clears graphic window Saves a session in a disk, possibly for printing at a later date © 1999 CRC Press LLC ... - tailieumienphi.vn
nguon tai.lieu . vn