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

Info icon This 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
Image of page 1

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

View Full Document Right 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
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern