Home

How to Perform Reduction Using MATLAB

|
Updated:  
2016-03-26 08:21:58
|
From The Book:  
MATLAB For Dummies
Explore Book
Buy On Amazon

You can perform reduction using MATLAB, and doing so requires only a couple of steps. Reduction lets you see the structure of what a matrix represents, as well as to write solutions to the system. MATLAB provides the rref() function to produce the Reduced Row Echelon Form (RREF). There is an interesting tool that you can use to see the steps required to produce RREF using any matrix as input.

The first step is to create the matrix. In this case, the example uses a magic square. Type A = magic(5) and press Enter. The magic() function will produce a magic square of any size for you. The output you see is

A =
 17 24  1  8 15
 23  5  7 14 16
  4  6 13 20 22
 10 12 19 21  3
 11 18 25  2  9

The second step is to perform the reduction. Type rref(A) and press Enter. Any nonsingular matrix will reduce to identity, as follows:

ans =
  1  0  0  0  0
  0  1  0  0  0
  0  0  1  0  0
  0  0  0  1  0
  0  0  0  0  1

You can use rref() to solve linear equations. In this case, if A*x=y and y=[1;0;0;0;0], then B=rref([A,y]) solves the equation. The following steps demonstrate how this works:

  1. Type y=[1;0;0;0;0]; and press Enter.

  2. Type A=magic(5); and press Enter.

  3. Type B=rref([A,y]) and press Enter.

    You see the following output:

    B =
    1.0000  0  0  0  0 -0.0049
      0 1.0000  0  0  0 0.0431
      0  0 1.0000  0  0 -0.0303
      0  0  0 1.0000  0 0.0047
      0  0  0  0 1.0000 0.0028
  4. Type x=B(:,6) and press Enter.

    You see the following output:

    x =
     -0.0049
     0.0431
     -0.0303
     0.0047
     0.0028

    At this point, you want to test the equation.

  5. Type A*x and press Enter.

    You see the following output:

    ans =
     0.9999
     -0.0001
     -0.0001
     -0.0001
     -0.0001

    Notice that the output values match the original value of y to within a small amount. In other words, the steps have proven the original equation, A*x=y, true.

About This Article

This article is from the book: 

About the book author:

Jim Sizemore is Professor of Physics and Engineering at Tyler Junior College. For over 25 years he s worked in the semiconductor and software industries as a process engineer, device physicist, and software developer and has been teaching college physics, engineering, and math for the last 13 years.

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.