Here\'s a complete guide for you to learn the basics of MATLAB implementation.\n
MATLAB is a mathematical software package specially designed for numerical computation, data manipulation and programming in both academia and technical industry. It basically works on the concept and algorithm of matrices.
Extraction of Matrix Elements
Using MATLAB Functions f (x)
In workspace, you can see the variables, functions, and matrices created.
This is the command window in MATLAB where you enter data in the form of codes.
This is where you can see the recent entries or deletions made in the command window.
A matrix is an array of the numbers, data, or expressions that can be arranged either in the form of rows and columns. Such as:
x=1 2 3 4
4 3 2 1
1 2 3 4
Where x is a vector named as a variable.
How to create matrix in MATLAB?
In MATLAB, you need to make use of the codes and symbols to define the vectors, rows, columns of the matrix. Suppose, you have data as a set of numbers 1, 2, 3, 4, 5, 6, 7, 8 (for example, these can be the responses you might have collected). For computing it in MATLAB, you must define it into a matrix using symbols (comma, semicolons, apostrophe etc. )
>> X= [1, 2, 3, 4, 5,6 , 7, 8,]
(>> is MATLAB Prompt)
1 2 3 4 5 6 7 8
>> X= [1; 2; 3; 4; 5; 6; 7; 8]
>> X= [1, 2, 3, 4,; 5, 6, 7, 8]
MATLAB would make it a matrix as:
1 2 3 4
5 6 7 8
During computation or data manipulation, you can refer to a particular element in the matrix by defining its position in the matrix. See the example below:
1 2 3 4
5 6 7 8
>> X (2,3)
ans = 7
Here, 2 and 3 refers to the row and column respectively. Therefore, you are given the 7 as the referred element through the command where ans is the randomly assigned name to the result. This process is called extraction of matrix elements.
You must note that you can only call the elements that are present in the matrix. If you give a command of X (4, 6), that is fourth row and sixth column, you would receive an error message as the above is 2x4 matrix. 4th row and sixth column doesn’t exist.
Apart from a particular entry in the matrix, you can also call a set of matrices using the command given below:
1 2 3 4
5 6 7 8
>> X (2:3, 2:4) (that is, 2nd row-3 column & 2nd row-fourth column respectively)
Colon (:) is used to extract the multiple elements of rows and columns. An entire row can also be extracted as:
>> X(1, :)
1, 2, 3, 4
MATLAB works with a set of in-built functions that help you do the calculation, computation, and implement the programmes seamlessly. Few of those are mentioned below:
sin= trigonometric sine cos= trigonometric cosinetan= trigonometric tangent asin=trigonometric inverse sine (arcsine) acos= trigonometric inverse cosine (arccosine)atan= trigonometric inverse tangent (arctangent)
exp= exponentiallog= natural logarithmabs= absolute valuesqrt= square rootrem= remainderround= round towards nearest integerfloor= round towards negative infinityceil round= towards positive infinity
max= largest componentmin= smallest componentlength= length of a vectorsort= sort in ascending ordersum= sum of elementsprod= product of elementsmedian= median valuemean= mean valuestd= standard deviation
You can perform the mathematical operations and calculations using the previously mentioned below:
X= [1, 2, 3, 4, 5, 6, 7, 8]
det= determinant of a square matrix inv= inverse of a matrix rank= rank of a matrix
rref= reduced row echelon form
eig= eigenvalues and eigenvector
poly= characteristic polynomial
norm= norm of matrix
lu= LU factorization qr QR factorization
chol= Cholesky decomposition
svd= singular value decomposition
zeros= matrix of zeros ones matrix of ones
diag= extract diagonal of a matrix or create diagonal matrices
triu= upper triangular part of a matrix
tril= lower triangular part of a matrix
rand= randomly generated matrixOther Matrix functions of MATLAB:Following are few more functions for matrix computation that makes it convenient for you:
To create an identity matrix, you must use the following command along with the specifications of the matrix rows and columns:
1 0 0
0 1 0
0 0 1
Or to create a 2, 2 matrix of zeros,
0 0 0
0 0 0
MATLAB provides a virtual environment for the external programmes to run efficiently. For this, you must use the exclamation mark (otherwise knowns as bang in MATLAB context) before the name of the programme or code you want to run.
>>!hello (the name of the programme)
So, if you wish to run Microsoft Excel in MATLAB, the command is as follows:
This would enable the windows to call the software MS Excel and returns you back to the command window of MATLAB where you can code further.
You can also run any program using the following command;
You can ask our experts at thesisandcode.com for professional help for PhD Matlab Implementation.
Drop your query with us at email@example.com