This is the basic introduction to Matlab. Creation of vectors is included with a few basic operations. Topics include the following: 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 a lot like the notation use in linear algebra. In the following tutorial, we will discuss some of the basics of working with vectors. If you are running windows or Mac OSX, you can start matlab by choosing it from the menu. To start matlab on a unix system, open up a unix shell and type the command to start the software: matlab. This will start up the software, and it will wait for you to enter your commands. In the text that follows, any line that starts with two greater than signs (>,>,) is used to denote the matlab command line. This is where you enter your commands. Almost all of Matlab’s basic commands revolve around the use of vectors. A vector is defined by placing a sequence of numbers within square braces: This creates a row vector which has the label “v”. The first entry in the vector is a 3 and the second entry is a 1. Note that matlab printed out a copy of the vector after you hit the enter key. If you do not want to print out the result put a semi-colon at the end of the line: Notice, though, that this always creates a row vector. If you want to create a column vector you need to take the transpose of a row vector. The transpose is defined using an apostrophe (‘): A common task is to create a large vector with numbers that fit a repetitive pattern. Matlab can define a set of numbers with a common increment using colons. For example, to define a vector whose first entry is 1, the second entry is 2, the third is 3, and sequentially through 8, you enter the following: If you wish to use an increment other than one that you have to define the start number, the value of the increment, and the last number. For example, to define a vector that starts with 2 and ends in 4 with steps of 0.25 you enter the following: You can view individual entries in this vector. For example to view the first entry just type in the following: This command prints out entry 1 in the vector. Also notice that a new variable called ans has been created. Any time you perform an action that does not include an assignment matlab will put the label ans on the result. To simplify the creation of large 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 0, 2, 4, 6, and 8, you can type in the following line: Matlab also 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: To be able to keep track of the vectors you create, you can give them names. For example, a row vector v can be created: Note that in the previous example, if you end the line with a semi- colon, the result is not displayed. This will come in handy later when you want to use Matlab to work with very large systems of equations. Matlab will allow you to look at specific parts of the vector. If you want to only look at the first three entries in a vector you can use the same notation you used to create the vector: For the most part Matlab follows the standard notation used in linear algebra. We will see later that there are some extensions to make some operations easier. For now, though, both addition subtraction are defined in the standard way. For example, to define a new vector with the numbers from 0 to -4 in steps of -1 we do the following: Additionally, scalar multiplication is defined in the standard way. Also note that scalar division is defined in a way that is consistent with scalar multiplication: With these definitions linear combinations of vectors can be easily defined and the basic operations combined: You will need to be careful. These operations can only be carried out when the dimensions of the vectors allow it. You will likely get used to seeing the following error message which follows from adding two vectors whose dimensions are different: Matlab Tutorial by Kelly Black is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License (2015).Based on a work at http://www.cyclismo.org/tutorial/matlab/. Matlab Tutorial by Kelly Black is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.Based on a work at http://www.cyclismo.org/tutorial/matlab/. Source.