User Tools

Site Tools


gibson:teaching:spring-2016:math445:lecture:vectors

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

====== Math 445 lecture 2: Vectors ====== ===== Vectors in math ===== Vectors are hugely important in math, science, engineering. In math, a vector is a list of numbers. E.g. this is a 3-d vector <latex> v = \left(\begin{array}{c} 4.3 \\ 5.9 \\ 0.1 \end{array} \right) </latex> In math, the components or elements of a vector are written with subscripts. E.g. for the above vector <latex> v_1 = 4.3, \quad v_2 = 5.9, \quad v_3 = 0.1 </latex> ===== Creating vectors with explicit lists in square brackets ===== In Matlab, there's a distinction between row vector and column vectors. You can construct **row vectors** by listing elements between **square brackets**, with either **spaces** or **commas** between. <code> >> v = [4.3 5.9 0.1] % assign a row vector into variable v v = 4.3000 5.9000 0.1000 </code> To create a column vectors, put semicolons between the elements. <code> >> v = [4.3; 5.9; 0.1] % assign a col vector into variable v v = 4.3000 5.9000 0.1000 </code> ===== Accessing elements with parentheses ===== In Matlab, you access the elements of a vector using **parentheses**. E.g. given the above vector v, you **get** the 2nd component of v this way <code> >> v(2) ans = 5.9000 </code> Note what happened there. We asked Matlab for the 2nd element of v. It **returned** the value 5.9 and assigned it to the default return variable ''ans''. Alternatively, the following will **assign** or **set** the value of the second component of v to another number. <code> >> v(2) = 2.7 v = 4.3000 2.7000 0.1000 </code> ===== The transpose operator ===== Note that last method. In Matlab, the apostrophe '' ' '' stands for the **transpose**. The transpose operator turns a row vector into a column vector, and vice versa. <code> >> v = [4.3 5.9 0.1] v = 4.3000 5.9000 0.1000 >> v' ans = 4.3000 5.9000 0.1000 >> u = v' u = 4.3000 5.9000 0.1000 >> w = u' w = 4.3000 5.9000 0.1000 </code>

gibson/teaching/spring-2016/math445/lecture/vectors.1453917441.txt.gz · Last modified: 2016/01/27 09:57 by gibson