Matrix Decomposition through a Sequence of MATLAB Operations

Haiyan Tian, University of Southern Mississippi,

Author Profile
Initial Publication Date: October 6, 2026
DOI | Cite this

Summary

Matrix decomposition is the process of representing a matrix as a product of several simpler matrices. This is an important technique in science and engineering since it converts a complex system into several easier ones. This activity provides students with the opportunity to:

(1) discover the connections between elementary row operations and matrix decomposition (or matrix factorization);

(2) experience the benefit of decomposition to solve a simplified version of an original problem efficiently.

Share your modifications and improvements to this activity through the Community Contribution Tool »

Learning Goals

In this activity, students are asked to apply row reduction operations to a matrix as a pathway to matrix decomposition. Using basic MATLAB commands and implementation, they connect the elementary row operations of linear algebra with a concrete computational procedure. Through a step-by-step decomposition process, students obtain a matrix factorization and then use the resulting factors to solve the original linear system. The activity is designed to strengthen conceptual understanding of matrix decomposition and its practical value as a computational method. In addition, the decomposition activity helps students recognize underlying patterns and develop a generalized version of the method that is applicable to a class of problems.

More specifically, students are asked to:

1.  apply step-by-step row operations to a given matrix A until they reduce it to an upper triangular matrix U;

2. express the operations done to A using a sequence of permutation and elimination matrices, and discover the features of these matrices;

3. record their operations using proper notations to discover the structure of A (such as, P A = L U) through the process;

4. solve a decomposed system to recognize the purpose of matrix decomposition;

5. generalize matrix decomposition;

The entire design is intended to connect implementation with symbolic meaning for generalization purposes. Throughout the project, students will digitally document their computations, results, and verification processes. They will engage in higher-level thinking by integrating mathematical representations of operations and developing generalizations for problems of similar type.

Context for Use

  • Students need prerequisite knowledge of linear algebra before learning the topic of matrix decomposition.
  • Students are encouraged to explore the live script feature of MATLAB for digitally documenting their work.

Description and Teaching Materials

This activity consists of four parts that will guide students from learning basic MATLAB commands to implementing and documenting a matrix decomposition.

Part A:

Introduction to MATLAB and Row Reductions

This section serves as an introduction on using MATLAB commands in linear algebra. Students learn how to enter matrices into MATLAB, perform elementary row operations, and obtain a row echelon form and a reduced row echelon form of a matrix.

The three elementary row operations on a matrix A:

  • Interchange two rows
  • Add a multiple of one row to another row
  • Multiply a row by a nonzero constant

Students complete an assignment in which they use a few MATLAB commands to do the required elementary row operations. They need to show both their commands and the outcomes of their implementations.

(A1) Define a specific matrix A with 3 rows and 4 columns, using A = [2, 4, 3, 5; 1, 2, -1, 4; 1, 2, -6, 7] in MATLAB.
(A2) First Approach: Perform a sequence of elementary row operations in MATLAB to obtain the reduced row echelon form (R-REF) of A.
(A3) Second Approach: Use MATLAB's built-in rref command to obtain the reduced row echelon form of A directly.
(A4) Compare the results obtained from two approaches and see whether they are the same.

 

Part B: 

LU Decomposition with Permutations for a Specific Square Matrix A

This section introduces LU decomposition where row permutations might be required in the process. It is also known as Gaussian elimination with row interchanges or Gaussian elimination with pivoting. This is an algorithm that will either determine that A is singular or decompose A when it is not singular. The process involves the use of two types of elementary row operations ( (a) interchanging two rows, (b) adding a multiple of one row to another row ), leading to matrix factorization.

(B1) In MATLAB, first define a 4-by-4 matrix A = [1, 1, 1, 0; 1, 1, -1, 0; 1, -1, 0, 1; 1, -1, 0, -1].

(B2) Let's first identify a permutation matrix P1 such that the (1, 1) entry of P1 A (i.e. after the permutation P1 ) has the absolute value greater than or equal to that of the entries below it in the first column. There are two possibilities for the (1, 1) entry of P1 A. It is either 0 or not 0. If it is 0, then the entire first column is 0, which means A is singular. If it is not 0, we identify a sequence of elimination matrices E2,1, E3,1, E4,1 to reduce P1 A until every entry below the pivot position is 0. Now define E1 = E4,1 E3,1 E2,1, and directly apply E1 to P1 A to find the result of  E1 P1 A. How does the result compare to A?

(B3) Based on the resulting matrix (E1 P1 A) constructed in step (2), we now identify a second permutation matrix P2 such that the (2, 2) entry of P2 (E1 P1 A) (i.e. after the permutation P2) has the absolute value greater than or equal to that of the entries below it in the second column. There are two possibilities for the (2, 2) entry of P2 (E1 P1 A). It is either 0 or not 0. If it is 0, then A is singular. If it is not 0, we identify a sequence of elimination matrices E3,2, E4,2 to reduce P2 (E1 P1 A) until every entry below the pivot position is 0. Now define E2 = E4,2 E3,2, and directly apply E2 to P2 (E1 P1 A) to find the result of E2 P2 (E1 P1 A).  How does the result compare to (E1 P1 A)? Continue the process using a similar fashion to determine P3 and E3  when possible so that the resulting matrix E3 P3 (E2 P2 (E1 P1 A)) is an upper triangular matrix U. If A is not singular, you will be able to transform it into an upper triangular matrix U, more specifically, E3 P3 E2 P2 E1 P1 A = U.

(B4) Show that E3 P3 E2 P2 E1 P1 A = U can be written as E3' E2' E1' P3 P2 P1 A = U, and decide how the matrices E1', E2', and E3' are related to E1, E2, E3, P1, P2, and P3.

(B5) Based on your work in the previous step, decide the matrices P, L and U for the given matrix A such that PA = LU, where L is a lower triangular matrix and U is an upper triangular matrix.

(B6) Verify in MATLAB that PA=LU using the P, L, and U you found in step (5).

(B7) If A is not singular, solve Ax=b, with b = [1; 2; 1; 5], through the following triangular systems.

  • L y = P b
  • U x = y

 

Part C: 

LU Decomposition with Permutations for an n by n Matrix

The process described in Part B can be generalized to handle a square matrix A of any size. If A is not singular, we can complete the LU decomposition with row permutations in the process. When A is not singular, we will be able to find a permutation matrix P, a lower triangular matrix L, and an upper triangular matrix U, such that PA=LU.

(C1) Consider any n by n matrix A. Develop an algorithm that either determines that A is singular or decomposes A when it is not singular. For a non-singular matrix A, describe the sequence of permutation matrices and elimination matrices to transform A into an upper triangular matrix U. 
(C2) For a non-singular matrix A, decide P (a permutation matrix), L (a lower triangular matrix), and U (an upper triangular matrix) using the permutation matrices and elimination matrices involved in (C1) such that PA = LU.

 

Part D: 

Documentation, Presentation, Reflection, and Revision

Students prepare a report that documents the implementation process, theoretical reasoning, and the verification of results. They will have an opportunity to present their work and answer questions from peers and the instructor for further revision and improvement.

Teaching Notes and Tips

The topic can be introduced and specified in one lecture. Students will be given one week to complete Parts A-D. The lecture provides an opportunity for students to present, ask questions, and meet expectations. The instructor offers hints and guidance to support successful completion of the assignment.

  • When a square matrix is non-singular, you will be able to reduce it to an identity matrix (its reduced row echelon form). You can use the command eye(4) to look at a 4 by 4 identity matrix by MATLAB. But students are reminded that they only need to obtain the row echelon form (instead of the reduced row echelon form) of A in Part (B).
  • A command such as A (2, : ) = A ( 2, : ) - A (1, : ) replaces the 2nd row of A with the difference of its 2nd row and 3rd row. A command like A (i, : ) = A (i, :) - A (1, :) updates its i-th row of A by subtracting 1st row from i-th row. With such operations and a pivot in the upper left corner, we can achieve the purpose of reducing a matrix such that every entry below the pivot is 0. But what we want here is to record these operations done to A using an elimination matrix E1. If you can determine E1, you will determine Ek, an elimination matrix at the k-th step below.
  • A command such as A (k+1, : ) = A ( k+1, : ) - A (k, : ) replaces the (k+1)-th row of A by subtracting k-th row from (k+1)-th row. A command like A (i, : ) = A (i, :) - A (k, :) updates its i-th row of A by subtracting k-th row from i-th row, with i > k. With such operations and a pivot in the k-k corner, we can achieve the purpose of reducing a matrix such that every entry below the pivot is 0. But what we want here is to record these operations done to A using elimination matrices Ek, with k=1, 2, ..., n-1.

Assessment

Parts A - C are graded, with points awarded for each answer based on its correctness and completeness.
Part D is intended for sharing/reflections/further improvement, and it provides a channel for the instructor to give individualized feedback to students, but no additional points will be awarded. Nevertheless, all students can benefit from the feedback provided.

References and Resources

  • D. S. Watkins, Fundamentals of Matrix Computations, 2nd Edition, Wiley, 2002.
  • R. L. Burden and J. D. Faires, Numerical Analysis, 9th Edition, Brooks/Cole, 2011.