Basic of MATLAB

1 / 19

# Basic of MATLAB - PowerPoint PPT Presentation

Here\'s a complete guide for you to learn the basics of MATLAB implementation.\n

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Basic of MATLAB' - thesisandcode

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### (Mathematical Laboratory)

USES OF MATLAB

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.

• Numerical Computation
• Data Manipulation & Plotting
• User-interface Development
• Implementation of Programming Languages
LEARNING THE BASICS

Creating Matrices

Extraction of Matrix Elements

Using MATLAB Functions f (x)

MATLAB Prompt

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.

### Creating Matrices

1

What is a matrix?

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. )

Steps to define row matrix in MATLAB:

• Assign a name to the vector using the sign of equals (=)
• Open the square brackets and enter the numbers separated by comma (,) and space in between. Close the square brackets once entered the entire set of numbers.
• You would use commas to make a row matrix. That is, the data would be visualized in the row form.

>> X= [1, 2, 3, 4, 5,6 , 7, 8,]

(>> is MATLAB Prompt)

X =

1 2 3 4 5 6 7 8

Steps to define column matrix in MATLAB:

• Assign a name (can be a variable) to the vector using the sign of equals (=)
• Open the square brackets and enter the numbers separated by semicolons (;) and space in between. Close the square brackets once entered the entire set of numbers.
• You would use semicolons to make a column matrix. That is, the data would be visualized in the column form.

>> X= [1; 2; 3; 4; 5; 6; 7; 8]

X =

1

2

3

4

5

6

7

8

Steps to Define Row by Column Matrix In MATLAB:

• Assign a name (can be a variable) to the vector using the sign of equals (=)
• Open the square brackets and enter the numbers separated by comma (,), semicolons (;) and space in between. Close the square brackets once entered the entire set of numbers.
• You would use comma for the numbers you want to align in row and semicolons for the ones to align in column. Your data can be visualized as below:

>> X= [1, 2, 3, 4,; 5, 6, 7, 8]

MATLAB would make it a matrix as:

X=

1 2 3 4

5 6 7 8

### Extracting Matrix Elements

2

Extracting particular element from matrix:

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:

X=

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.

Extracting the submatrices from the matrix

Apart from a particular entry in the matrix, you can also call a set of matrices using the command given below:

X=

1 2 3 4

5 6 7 8

>> X (2:3, 2:4) (that is, 2nd row-3 column & 2nd row-fourth column respectively)

ans=

3 4

7 8

Colon (:) is used to extract the multiple elements of rows and columns. An entire row can also be extracted as:

>> X(1, :)

ans=

1, 2, 3, 4

### Using Matrix Functions in MATLAB

3

In-built functions f(x) of MATLAB

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

How to use functions for calculation:

You can perform the mathematical operations and calculations using the previously mentioned below:

X= [1, 2, 3, 4, 5, 6, 7, 8]

sum (X)

ans= 36

Also,

max (X)

ans=8

size= size of a matrix

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

eye=identity matrix

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 matrix

Other Matrix functions of MATLAB:Following are few more functions for matrix computation that makes it convenient for you:

How to use Matrix Functions:

To create an identity matrix, you must use the following command along with the specifications of the matrix rows and columns:

>>eye (3,3)

ans=

1 0 0

0 1 0

0 0 1

Or to create a 2, 2 matrix of zeros,

>>zeroes (3,3)

ans=

0 0 0

0 0 0

Running A Programme in MATLAB:

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:

>> !excel.exe

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;

demo <enter>

### THANKS!

Any questions?

You can ask our experts at thesisandcode.com for professional help for PhD Matlab Implementation.

Drop your query with us at contact@thesisandcode.com