About MATLAB MATLAB is an interactive software which has been used recently in various areas of engineering and scientific applications. It is not a computer language in the normal sense but it does most of the work of a computer language. Writing a computer code is not a straightforward job, typically boring and time consuming for beginners. One attractive aspect of MATLAB is that it is relatively easy to learn. It is written on an intuitive basis and it does not require in-depth knowledge of operational principles of computer programming like compiling and linking in most other programming languages. This could be regarded as a disadvantage since it prevents users from understanding the basic principles in computer programming. The interactive mode of MATLAB may reduce computational speed in some applications. The power of MATLAB is represented by the length and simplicity of the code. For example, one page of MATLAB code may be equivalent to many pages of other computer language source codes. Numerical calculation in MATLAB uses collections of well-written scientific/mathematical subroutines such as LINPACK and EISPACK. MATLAB provides Graphical User Interface (GUI) as well as three-dimensional graphical animation. In general, MATLAB is a useful tool for vector and matrix manipulations. Since the majority of the engineering systems are represented by matrix and vector equations, we can relieve our workload to a significant extent by using MATLAB. The finite element method is a well-defined candidate for which MATLAB can be very useful as a solution tool. Matrix and vector manipulations are essential parts in the method. MATLAB provides a help menu so that we can type the help command when we need help to figure out a command. The help utility is quite convenient for both beginners and experts.
Vector and Matrix Manipulations Once we get into MATLAB, we meet a prompt » called the MATLAB prompt. This prompt receives a user command and processes it providing the output on the next line. Let us try the following command to define a matrix. >> A=[1,3,6;2,7,8;0,3,9] Then the output appears in the next line as shown below. A= 1 2 0 3 7 3 6 8 9
Thus, a matrix is entered row by row, and each row is separated by the semicolon(;). Within each row, elements are separated by a space or a comma(,). Commands and variables used in MATLAB are case-sensitive. That is, lower case letters are distinguished from upper case letters. The size of the matrix is checked with >> size(A) ans = 3 3 In order to find the transpose of matrix A, we type
Transpose of a matrix >> A' The result is
1 2 0 ans = 3 7 3
6 8 9 Column or row components MATLAB provides columnwise or rowwise operation of a matrix. The following expression >> A(:,3) yields ans = 2
6 8 9 which is the third column of matrix A. In addition, >>A(:,1) represents the first row of A as ans = 1 3 6 We can also try >> A(:,1)+A(:,3) as addition of the first and third rows of A with the result ans= 1 6 15 Now let us introduce another matrix B as >> B = [3,4,5; 6,7,2:8,1,0]; Then there seems to be no output on the screen. MATLAB does not prompt output on the screen when an operation ends with the semicolon (;). If we want to check the B matrix again, we simply type >>B The screen output will be 3 4 5 B = 6 7 2 8 1 0 Matrix addition >> C = A + B 4 8 7 4 11 9 Adding two matrices is straightforward like
C = 8 14 10
In order to subtract matrix B from matrix A, we type
>> C = A-B -2 C = -4 -1 0 1 6
- 8 2 9 Note that C is now a new matrix, not the summation of A and B anymore. Matrix multiplication >> C = A*B 69 C= 112 90 Matrix Functions Manipulation of matrices is a key feature of the MATLAB functions. MATLAB is a useful tool for matrix and vector manipulations. Collections of representative MATLAB matrix functions are listed in Table 1. Examples and detailed explanations are provided for each function...