MatlabTut

# MatlabTut - Matlab Tutorial Francesco Franco Matlab is a...

This preview shows pages 1–4. Sign up to view the full content.

Matlab ® Tutorial Francesco Franco Matlab ® is a software package that makes it easier for you to enter matrices and vectors, and manipulate them. The interface follows a language that is designed to look like the notation used in linear algebra. This tutorial guides you in the first steps for using Matlab ® . Start the program, The main window is subdivided in three windows. The Command Window is the one where you enter your commands (after a >> which is used to denote a command line). I Vectors : Almost all of Matlab ® Basic commands revolve around the use of vectors. To simplify the creation of vectors, you can define a vector by specifying the first entry, an increment, and the last entry. Matlab ® will automatically figure out how many entries you need and their values. For example, to create a vector whose entries are 1,3,5,7, type the following >> 1:2:7 ans = 1 3 5 7 Matlab ® keeps track of the last result. In the previous example a variable “ans” is created. To look at the transpose of the previous result, enter the following (‘ is the transpose operator): >> ans' ans = 1 3 5 7 To be able to keep track of the vectors you create, you can give them names. To create a row vector v: >> v=[1:2:7] v = 1 3 5 7 >> v v = 1 3 5 7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
If you add a semi-colon (;) at the end of the command line, the result is not displayed. Matlab ® will allow you to look at specific parts of the vector, thus to work with the first 3 elements of v: >> v(1:3) ans = 1 3 5 Once you master the notation you are free to perform other operations: >> v(1:3)-v(2:4) ans = -2 -2 -2 Defining a matrix is similar to defining a vector. To define a matrix, you can treat it like a column of row vectors (note that the spaces are required!): >> A= [ 1 2 3; 3 4 5; 6 7 8] A = 1 2 3 3 4 5 6 7 8 You can also treat it like a row of column vectors: >> B= [[1 2 3]' [2 4 7]' [3 5 8]'] B = 1 2 3 2 4 5 3 7 8 Now you have a lot of variables defined. If you lose track of what variables you have defined, the whos command will let you know all of the variables you have in your work space. >> whos Name Size Bytes Class A 3x3 72 double array B 3x3 72 double array ans 1x3 24 double array v 1x4 32 double array Grand total is 25 elements using 200 bytes
You can of course multiply matrices and vectors (be careful that they must have the right size): >> A*v(1:3)' ans = 22 40 67 You can work with different parts of a matrix, just as you can with vectors, thus to work with the submatrix A (1:2,2:3) : >> A(1:2,2:3) ans = 2 3 4 5 Once you are able to create and manipulate a matrix, you can perform many standard operations on it. For example, you can find the inverse of a matrix. You must be careful, however, since the operations are numerical manipulations done on digital computers, (calculate the determinant of A…maybe using matlab the command is det(A)), the software

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 12

MatlabTut - Matlab Tutorial Francesco Franco Matlab is a...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online