matlab1 - Linear Algebra Using Matlab 1 MATLAB is short for...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Linear Algebra Using Matlab MATLAB is short for “MATrix LABoratory”. It provides a friendly environment for manipu- lating matrices and also contains a large number of built routines that make matrix algebra simple. Basic Matrix Commands If M is a matrix in MATLAB, then M(2,3) denotes the entry in the second row, third column of M. For example: >> M =[ 2 4 5 -1; 3 2 -2 1; 0 3 -2 1] M = 2 4 5 -1 3 2 -2 1 0 3 -2 1 >> M(2,3) ans = -2 Try M(3,2) . Matrix manipulation is made easy by the ‘all’ operator ‘:’. For instance, to access all elements in the second row of M , >> M(2,:) ans = 3 2 -2 1 Similarly, all elements of the first column of M >> M(:,1) ans = 2 3 0 We can also easily refer to sub-matrices. For example if we wanted the matrix made up of both the first and third rows of M : >> M([1 3],:) ans = 2 4 5 -1 0 3 -2 1 To produce the matrix formed by eliminating the second row and third column of M : >> M([1 3],[1 2 4]) ans = 2 4 -1 0 3 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Linear Algebra Using Matlab 2 Notice this allows us to easily interchange individual rows or columns. For example, if we wanted to switch rows 1 and 3 of M : >> M([1 3],:) = M([3 1],:) M = 0 3 -2 1 3 2 -2 1 2 4 5 -1 Finally, Matlab makes taking the transpose of a matrix easy. Try typing M’ . Elementary Row Operations Suppose we have a set of equations given by Mx = 0 where M is the matrix defined above. Our solution technique involves reducing the matrix using elementary row operations. These are easily accomplished in Matlab without worrying about keeping the arithmetic straight. Start by reloading M . (Note, placing a semicolon at the end of a Matlab line suppresses the output that we don’t care to see.) >> M =[ 2 4 5 -1; 3 2 -2 1; 0 3 -2 1]; Now, start the reduction by dividing the first row by the first element. Since we are working with
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/16/2011 for the course MATH 216 taught by Professor Mckinley,s during the Fall '08 term at Duke.

Page1 / 7

matlab1 - Linear Algebra Using Matlab 1 MATLAB is short for...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online