You are on page 1of 20

OPT211 Lab 3 Spring 2019

The Very Basics of Linear Algebra

Introduction:
The purpose of this lab is to familiarize you with basic features of matrices in Matlab, introduce
matrix and array syntax, and learn how to perform some simple calculations using matrices. This
is essentially a crash course in very basic linear algebra. If you have not yet taken linear algebra,
after completing this lab, you will know how to use Matlab as a tool for that course, when you
take it. If you have taken linear algebra, this will show you the basic of how to manipulate
matrices in order to solve linear problems using Matlab.

Citation: Portions of this lab were adapted from the textbook: Linear Algebra with Applications:
Second Edition, by Otto Bretscher. The textbook was published by Prentice Hall of Upper Saddle,
New Jersey in 2001. This book served as the textbook for MTH165, “Linear Algebra with
Differential Equations” on the order of a decade ago.

Part 1: Basic Matrix Syntax, Manipulation, and Calculation


I will not review how to define matrices here. This was covered in lab 1 of this course, so if you
do not remember how to do that, please consult lab 1 or come to office hours and we can go over
it.

All of the matrices which will be used for this lab will be defined in a script called “matrices.m”.
A template for this script can be downloaded with the lab materials for lab 3 on Blackboard.
Please download this file and copy it into the working directory you use for this course. When
you have done this, “matrices.m” should show up in your current folder in Matlab. As part of
the pre-lab assignment, you will use Appendix 1 of this lab (located at the end of this document)
to populate the template with matrices. I have included the script template as Appendix 2.

Execute the m-file:

>> matrices

Nothing should show up in your command window. If you run the help command for this script
(help matrices), you will notice that this was the intention of the script. As described there,
you will see that several matrices have now appeared in your workspace. The beauty of this is
that all of these matrices can now be called up in the command window. You may close the m-
file editor window. All further work for this lab will be completed in the command window.

1|Page
Let’s call up one of these matrices so you can see what I mean. Execute the following command:

>> A51

You should see this:

>> A51

A51 =

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

>>

Here, Matlab is representing the following 5x5 matrix:

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

This is a 5 row, 5 column matrix. Matrices are typically defined as mxn, where m is the number
of rows and n is the number of columns. Given that, a 1x4 matrix has 1 row and 4 columns:

𝐴1𝑥4 = [𝑎 𝑏 𝑐 𝑑]

while a 4x1 matrix has 4 rows and 1 column:


𝑎
𝐴4𝑥1 = [𝑏
𝑐]
𝑑

this is an important naming convention, so please try to keep it in mind.

Let’s manipulate our 5x5 matrix, A5,1, a little bit. We can pick and choose individual rows or
columns from the matrix using some basic matrix syntax. When we follow the name of an array
or matrix with a set of parentheses, this tells Matlab we are going to do something with a
particular part of the array/matrix.

2|Page
Execute the following command:

>> A51(:,3)

You should see this:

>> A51(:,3)

ans =

3
8
13
18
23

>>

Here, we told Matlab to select the third column of the matrix A5,1. Now, execute the following
command:

>> A51(3,:)

You should see this:

>> A51(3,:)

ans =

11 12 13 14 15

>>

This time, we’ve selected the third row of the matrix A5,1. Execute the following command:

>> A51(3,3)

You should see this:

>> A51(3,3)

ans =

13

>>

3|Page
Here, we asked Matlab to select the number in the third column of the third row of the
matrix A5,1.

So, when you use the syntax described here, you can select different portions of a matrix:

>> A(m,n)

Where, A is the matrix in question, m is the number of the row you wish to select, and n is
the number of the column you wish to select.

If you use the colon (:), this is telling Matlab to select either the entire row or entire column
(depending on where you include the colon). To show this, try executing:

>> A51(:,:)

This should return the entire 5x5 matrix, whereas when we used the colon before, we
selected only a single row or column.

We can use this syntax in many useful ways. We will look at two here. First, we can use this
syntax to name a new variable that is defined by a single row or column from a larger matrix, or
even a single value of that matrix. Execute the following two commands:

>> Atest=A51(:,4)

>> Ctest=A51(5,2)

You should have created a new matrix called Atest which is a 5x1 matrix corresponding to the
fourth column of matrix A5,1 and also a new scalar (single number), Ctest, which corresponds to
the second entry of the fifth row of matrix A5,1. You can now use these new variables/scalars in
any way you wish.

If you have a large matrix including a lot of data or information and you wish to select a certain
portion of it, this strategy can help you do that easily.

Secondly, we can also use this syntax to replace a certain portion of a matrix. As an example,
execute the following command:

>> A51(3,3)=42

4|Page
You will see the following output:

A51 =

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

If you look at the third row and the third column, this command changed the original contents of
the third column of the third row to a value of 42. This is a very powerful tool; however, it can
be dangerous. You can easily overwrite data if you do not use this command properly.

You can also use this syntax to replace entire rows or columns of a matrix, but we will not do that
here.

Now, let’s perform a couple of different matrix operations.

In lecture, we discussed the inner product, so I will not expressly describe it here. Call up matrices
A41, B41, and B42 in the command window so you can see what they look like. A41 is a 4x4
matrix while, B41 and B42 are 1x4 and 4x1 matrices respectively.

In Matlab, the * operator will compute the inner product between two matrices, but only if the
matrix dimensions allow Matlab to compute the product.

Execute the following command:

>> A41*B41

You should have generated an error. This is because matrix B41 is a 1 row, 4 column matrix and
we are trying to compute the product between a 4x4 matrix and it, which is not possible according
to the rules of matrix math. Now try:

>> A41*B42

This should generate a 4x1 matrix. Here, the inner product worked because we provided Matlab
with the correct matrix dimensions to perform the inner product:

1 2 3 4 5 150
[2 4 7 11] [10] = [ 375 ]
3 7 14 25 15 795
4 11 25 50 20 1505

5|Page
If you have a matrix which is the correct size but is in the wrong format (like our 1x4 matrix
instead of a 4x1 matrix), there is a tool that can be used to convert the matrix to the correct
orientation.

Execute the following command:

>> B41.'

where, the ‘ is a single quotation mark. The .’ operator is the vector, or matrix transpose
operator which will convert the rows of a matrix or array into columns or vice-a-versa. Your
output should be a 4x1 matrix now matching B42.

Execute the following command now:

>> A41*B41.'

This should yield the correct inner product now and not show any errors. It should also show
you that the transpose sits high in the Matlab order of operations (higher than multiplication and
division, but below parentheses).

In lecture, the idea of a matrix inverse was introduced. The matrix inverse is the equivalent of
calculating 1/A for a matrix (where A is a matrix). The catch with matrix inverses and
determinants is that the matrix must be “square” to be invertible. A square matrix has the same
number of rows and columns. Matlab can easily calculate the inverse of a square matrix for you;
however, not all square matrices are invertible, and Matlab may produce an error if you try to
invert a non-invertible matrix. Let’s show how that works.

There are a couple of ways to invert a matrix in Matlab. First, call up A21 and A22 in the
command window and see that they are standard 2x2 matrices: Execute the following two
commands:

>> A21^-1
>> inv(A21)

In both cases, the answer is:

ans =

8.0000 -3.0000
-5.0000 2.0000

6|Page
This new 2x2 matrix is the inverse of matrix A21. You can either raise a matrix to the -1 power or
you can use the inv(A), or inverse, function Matlab has built in. I would get in the habit of using
the inv(A) function. It’s handy and there are less syntax pitfalls than using the ^-1 operation.

Now, execute the following command:

>> inv(A22)

You should see this:

>> inv(A22)
Warning: Matrix is singular to working precision.

ans =

Inf Inf
Inf Inf

>>

“Inf” in Matlab syntax means “infinity.” The warning is telling you that the matrix is singular,
or in other words, is not invertible. Even though the matrix looks innocuous enough, it does not
have an inverse. There is a feature of the matrix which can tell us why this matrix is not invertible.
That feature was mentioned in lecture. It is the determinant. Recall from lecture, that the inverse
of a 2x2 matrix:

𝑎 𝑏
𝐴= [ ]
𝑐 𝑑
is given by:

1 𝑑 −𝑏 1 𝑑 −𝑏
𝐴−1 = 𝑖𝑛𝑣 (𝐴) = [ ]= [ ]
|𝐴| −𝑐 𝑎 det(𝐴) −𝑐 𝑎
1 𝑑 −𝑏
= [ ]
𝑎𝑑 − 𝑏𝑐 −𝑐 𝑎

The determinant of the matrix A, is defined by |A|= det(A) = ad-bc for a 2x2 matrix. Matlab can
easily compute determinants using the det(A) function.

7|Page
Compute the determinant of A21:

>> det(A21)

ans =

1.0000

>>

This is a perfectly reasonable determinant.

Now compute the determinant of A22:

>> det(A22)

ans =

>>

It should be obvious to you that this is a problem. In the formula for the inverse (as shown above),
the inverse matrix contains the term 1/det(A). Dividing by zero is always a problem, so in this
case, this is why matrix A22 is not invertible.

There is a nice handy formula for calculating the inverse and the determinant of a 2x2 matrix, but
simple formulas do not exist for larger square matrices. Regardless of this, Matlab does not have
a problem calculating the inverse or determinant of a larger square matrix. To demonstrate this,
calculate the inverse and determinant of the matrix A41.

If you wish (this is not required, but if you are moving quickly through this lab, go ahead and try
it), attempt to take the determinant and inverse of matrix B41 and B42. You will notice that
Matlab produces an error and tells you that the matrix must be square to calculate these values.

8|Page
Part 1b: The Identity Matrix

This section is really a continuation of part 1, but skip it and complete part 2 before attempting it.
It’s more important for you to get through part 2 during the lab section. You can easily complete
this section on your own (in fact, it’s included as part of the post-lab assignment, so that is
accounted for already).

As discussed in lecture, the identity matrix is the equivalent of a scalar ‘1’ but for matrices.
Computing the inner product of a square matrix with the identity matrix of the same size will
yield the original matrix again (just like multiplying any scalar/number by 1 will yield the
original scalar/number). Identity matrices look like this:

1 0 0
1 0
𝐼2 = [ ], 𝐼3 = [0 1 0]
0 1
0 0 1
Here, I only show the 2x2 and 3x3 identity matrices, but larger identity matrices will exhibit the
same properties (a diagonal array of ones surrounded by zeros).

Matlab has a function which will generate the identity matrix of any square size. This is the
eye(n) function where n is the size of the matrix. In the command window, generate the identity
matrices for n=1, 2, 3, 4, and 5. Copy all of these into the post-lab portion of your lab notebook.
Note that the eye(1) command yields the scalar 1 which demonstrates the similarities between
the scalar 1 and the identity matrices.

Now, execute the following commands:

>> A21*eye(2)
>> A22*eye(2)
>> A41*eye(4)
>> A51*eye(5)

Each of these commands should yield the same Axx matrix which you started with. This is a
property of the identity matrix as described above:

𝐴𝐼 = 𝐴
There is one more property of the identity matrix which is particularly interesting. When you
take the inner product of an invertible matrix with its inverse, it will yield the identity matrix:

𝐴𝐴−1 = 𝐼
9|Page
Verify this by executing the following commands:

>> A41*inv(A41)
>> A21*inv(A21)

NOTE: If you were to do this with A22 or A51, you will find that Matlab produces a singularity
warning and nonsensical answers. This is because A22 and A51 are non-invertible.

Part 2: Solving Linear Systems in Matlab

I introduced linear systems of equations in lecture. A linear system of equations is a group of


inter-related equations which do not contain any variables raised to a power higher than one.
When we describe equations as being inter-related, we mean that the equations are dependent
upon one another. In this case, we are looking for a set of solutions which satisfy all equations in
the system, simultaneously. For the sake of our work here, we are going to limit our discussion
to systems containing the same number of variables as there are equations. There are systems for
which there are other arrangements, but we will not consider those here.

There are many ways to represent and express a linear system of equations:

𝑎𝑥 + 𝑏𝑦 + 𝑐𝑧 = 𝐿 (I) 𝑎 𝑏 𝑐 𝐿
{𝑑𝑥 + 𝑒𝑦 + 𝑓𝑧 = 𝑀 (II) ↔ 𝑥 [𝑑 ] + 𝑦 [𝑒 ] + 𝑧 [𝑓 ] = [𝑀]
𝑔𝑥 + ℎ𝑦 + 𝑖𝑧 = 𝑁 (III) 𝑔 ℎ 𝑖 𝑁
𝑎 𝑏 𝑐 𝑥 𝐿 𝑎 𝑏 𝑐 𝐿
↔ [ 𝑑 𝑒 𝑓 ] [ 𝑦 ] = [𝑀 ] ↔ [ 𝑑 𝑒 𝑓 | 𝑀 ]
𝑔 ℎ 𝑖 𝑧 𝑁 𝑔 ℎ 𝑖 𝑁
𝑎 𝑏 𝑐 𝐿
↔ [𝑑 𝑒 𝑓 𝑀 ]
𝑔 ℎ 𝑖 𝑁

Each of these was described in the lecture, but I will very briefly describe them here in case you
are in need of a refresher (from left to right, top to bottom – Each formulation is separated by the
↔ symbol).

10 | P a g e
The first formulation shows three equations with three unknowns. From an algebraic standpoint,
this is the easiest form to conceptualize. Simply put, we have three equations with three variables
(x,y,z) each with their own, independent constants. This is referred to as a linear system with
three equations and three unknowns (the unknowns are x, y, and z).

The second formulation is the vector form of the linear equation. Here, we represent each variable
as a vector with three components (each component has a magnitude given by the constants
defined by the equations).

The third formulation is the basic linear algebra format. The constants are contained in a 3x3
matrix (A) in front of a 3x1 matrix (𝑥⃑) and the “answers” (the right side of each equation) are
represented by another 3x1 matrix (B).
This gives a linear algebraic equation of:

𝐴𝑥⃑ = 𝐵

which is the standard form for a linear system of equations in linear algebra.

This system can be solved by moving the A matrix to the right side of the equation:

𝑥⃑ = 𝐴−1 𝐵

𝑥 𝑎 𝑏 𝑐 −1 𝐿 𝑎 𝑏 𝑐 𝐿
[𝑦] = [𝑑 𝑒 𝑓] [𝑀] = 𝑖𝑛𝑣 [𝑑 𝑒 𝑓 ] [𝑀]
𝑧 𝑔 ℎ 𝑖 𝑁 𝑔 ℎ 𝑖 𝑁
In other words, we can solve the system of equations by taking the inner product of the inverse
of the A matrix with the B matrix. The observant student will remark that this will only work if
the matrix A is invertible. If matrix A is not invertible, the system of equations will have either
an infinite number of solutions or no solutions.

In order to determine which of these cases will apply to a given linear system of equations, we
use the fourth formulation of the linear system:

𝑎 𝑏 𝑐 𝐿
[𝑑 𝑒 𝑓 | 𝑀]
𝑔 ℎ 𝑖 𝑁
This is called the augmented matrix. The augmented matrix combines the A and B matrices into
a single matrix separated by a vertical line: [A|B]. This formulation allows us to perform a series

11 | P a g e
of mathematical operations on the entire system quickly and easily to determine the
characteristics of the system. These manipulations are covered in detail in any linear algebra
class, but we will not talk about them here.

The final formulation simply takes out the vertical line, creating a standard 3x4 matrix:

𝑎 𝑏 𝑐 𝐿
[𝑑 𝑒 𝑓 𝑀]
𝑔 ℎ 𝑖 𝑁
More times than not, this is the form which will be used as an input for Matlab when solving a
system of equations.

In class, I described a simple 2x2 system of equations and showed how you might go about
solving it manually, using conventional algebra. I’ll have you demonstrate this in your post-lab,
but first, let’s remind ourselves of the system of equations:

2𝑥 + 6𝑦 = 10 (I)
{
−5𝑥 + 4𝑦 = −3 (II)

I have already programmed the A and B matrix for this system into Matlab for you in the
matrices.m script. They are represented by A23 and B23.

There are several methods through which we can solve this system of equations in Matlab.

First, we can use our equation:

𝑥⃑ = 𝐴−1 𝐵

Here, the 𝑥⃑ will be a 2x1 matrix which represents x and y:

𝑥 2 6 −1 10
𝑥⃑ = [𝑦] = [ ] [ ]
−5 4 −3
Matlab can accept the following commands to solve the system in this way:

>> A23\B23;
>> A23^-1*B23;
>> inv(A23)*B23;

Execute all three of these commands and verify that you get the same answer each time. I
recommend using the third option, generally. The first option (with the \ operator) is a pretty

12 | P a g e
specialized and fairly rarely used operator. It is called the “left matrix division operator.” It is
easily confused with /, so I recommend using a different form.

We can also solve this system using an augmented matrix formulation. First, we will create an
augmented matrix. Execute the following command:

>> AA23 = [A23 B23]

AA23 =

2 6 10
-5 4 -3

>>

This combined A23 and B23 to create a 2x3 augmented matrix to represent the system. We can
solve this system with one command line in Matlab (execute this):

>> rref(AA23)

ans =

1.0000 0 1.5263
0 1.0000 1.1579

The rref(A) function stands for “reduced row echelon form of A.” This process uses something
called Gauss-Jordan elimination to simplify matrix A to a form which represents the features of
the linear system (All of this is described in detail in a linear algebra class, but I won’t do that
here). Basically, the reduced augmented matrix looks like the 2x2 identity matrix with a 2x1
matrix next to it. Let’s think about what the augmented matrix represents and it will help us
understand what this new matrix means. Recall that the augmented matrix is [A|B]. Now we
have [I|B’]. In terms of our linear system of equations, this reduces our linear equation to:

𝐼𝑥⃑ = 𝑥⃑ = 𝐵′
So the third column of our reduced augmented matrix contains the answers for x and y for our
system of equations. If you look at the results you calculated earlier, you will see that they match
exactly with this third column.

This method for solving a linear system is particularly useful because it will give you the single
solution (if the system only has one), but it will also tell you whether the system has no solutions

13 | P a g e
or an infinite set of solutions (and the form those infinite solutions take). The other method (𝑥⃑ =
A-1B) cannot tell you whether your system has no solutions or an infinite number of solutions.

To demonstrate this, we will solve three systems of linear equations (All of which are scripted
into your workspace already):

𝑥 + 2𝑦 + 3𝑧 = 39 (I)
1. { 𝑥 + 3𝑦 + 2𝑧 = 34 (II)
3𝑥 + 2𝑦 + 1𝑧 = 26 (III)
Represented by A31 and B31 in matrices.m

2𝑥 + 4𝑦 + 6𝑧 = 0 (I)
2. { 4𝑥 + 5𝑦 + 6𝑧 = 3 (II)
7𝑥 + 8𝑦 + 9𝑧 = 6 (III)
Represented by A32 and B32 in matrices.m

𝑥 + 2𝑦 + 3𝑧 = 0 (I)
3. { 4𝑥 + 5𝑦 + 6𝑧 = 3 (II)
7𝑥 + 8𝑦 + 9𝑧 = 0 (III)
Represented by A33 and B33 in matrices.m

You can solve each of these systems with a single line in the command window:

>> rref([A3x B3x])

where x is the number of the linear system (1, 2, or 3). Go ahead and solve all three systems using
this single line approach in Matlab.

14 | P a g e
Let’s look at the answers from all three systems. Your output should be the Matlab equivalent of
these augmented matrices:

1 0 0 2.75
1. [0 1 0 |4.25]
0 0 1 9.25
As in the case of our 2x2 system, we see this system has the identity matrix on the
left and reasonable values on the right.

This system has one solution where:

x=2.75,
y=4.25,
z=9.25.

1 0 −1 2
2. [0 1 2 |−1]
0 0 0 0
This case is different. We do not have the identity matrix. Let’s look at the three
equations we have left:

𝑥−𝑧 =2 (I)
{𝑦 + 2𝑧 = −1 (II)
0=0 (III)

Here, we have three valid equations (yes, 0=0), but for any value of z I put into
equations I and II, I get a different (although completely valid) answer for x and y.
This system has an infinite number of solutions.

It is important to note, again, that using the A-1B approach will not yield this result.
I will ask you to show this in the post-lab.

15 | P a g e
1 0 −1 0
3. [0 1 2 |0]
0 0 0 1
This case is different, still. Again, we don’t have the identity matrix, but something
is clearly wrong. Let’s look at the three equations we have left:

𝑥−𝑧 =0 (I)
{𝑦 + 2𝑧 = 0 (II)
0=1 (III)

Clearly, 0 ≠ 1. This simply cannot be . This is an example of a linear system which


has no solutions.

It is important to note, again, that using the A-1B approach will not yield this result.
I will ask you to show this in the post-lab.

This may all seem somewhat confusing right now if you do not know linear algebra well. When
you take that course, look at this lab again, and hopefully it will seem a lot clearer.

If you want to know more about this now, please come to office hours and we will talk about it.

16 | P a g e
Pre-lab.

If you haven’t yet, please read through the lab. You really won’t be able to complete the pre-
lab until you do this.

1. Prepare your digital lab notebook in Microsoft Word. This should outline the various
sections of this lab; designate locations for copying in any completed scripts, command
window content, and generated figures; and include the proper fonts and formatting as
described in lab 1.

2. In this lab, you will be performing matrix operations on a given set of matrices. The
matrices can be found in Appendix 1 at the end of this lab document. In Appendix 2, you
will find a template for an m-file. The template contains all information required to input
the matrices in Appendix 1 except the definitions of the matrices themselves. I have
provided you with an m-file version of the Appendix 2 template, called ‘matrices.m’.
Download this from Blackboard and place it in the current Matlab folder you will be using
for this lab.

Edit this template to include the matrices as described in Appendix 1.

Copy your completed script into your lab notebook document (question 1 of this pre-lab).
Make sure you upload this notebook file as part of your pre-lab submission. Also, be sure
to upload your edited m-file in your pre-lab submission.

3. Check that your m-file, ‘matrices.m’ is correct. Execute ‘matrices.m’ in the command
window. This will populate the workspace with all of the various matrices the m-file
contains. Verify the matrices match the definitions in Appendix 1 by displaying each
matrix in the command window (you can simply type each matrix name into the
command window and press ‘Enter’ or ‘Return’).

Copy your command window output into your lab notebook template (question 1 of this
pre-lab) and upload this file (which should now include pre-lab question 2 and 3 output)
to Blackboard with your ‘matrices.m’ file.

BONUS: There is a simple way to verify all matrices are correct by editing your
‘matrices.m’ file slightly (without adding any additional lines of code) and executing a
single command in the command window. I’ll give several bonus points to those who
complete problem 3 this way.

4. How long did it take you to complete this pre-lab assignment?

17 | P a g e
Post-lab.

1. Complete part 1b of the lab. In doing so, verify in Matlab that:

a. 𝐴𝐼 = 𝐴
b. 𝐴𝐴−1 = 𝐼

2. Using Matlab, attempt to take the determinant and inverse of matrix B41 and B42. What
happened? Why? Show the command window output.

3. Using standard algebraic techniques (by hand, on paper, showing all work), solve the
following systems of equations:

2𝑥 + 6𝑦 = 10 (I)
a. {
−5𝑥 + 4𝑦 = −3 (II)

𝑥 + 2𝑦 + 3𝑧 = 39 (I)
b. { 𝑥 + 3𝑦 + 2𝑧 = 34 (II)
3𝑥 + 2𝑦 + 1𝑧 = 26 (III)

A method for doing this was discussed in class, but use any algebraic method you are
comfortable with. The idea here is to not use a computer (except for division of constants).

4. Take the determinant of matrices A32 and A33. What does this tell you about whether
these matrices are invertible? Take the inverse of these as well. Are the results reasonable?
You know the second system has infinitely many solutions and the third system has no
solutions. Can you tell this difference between A32 and A33 through these calculations?

5. Were you able to complete the lab during the lab time allotted? If not, how much time
outside of lab did it take you to complete the body of this lab (excluding the pre-lab and
post-lab questions).

6. How long did it take you to complete the post-lab assignment?

BONUS!!!
For some extra points, go ahead and create 5 different systems of linear equations (3 equations
with 3 unknowns or larger systems - not from the lab) and use Matlab to solve them. Tell me
what the solution is (if there is a single solution), what form the solutions take if there are an
infinite number of solutions, or that there are no solutions (if there are no solutions). Show
me your Matlab output. Did you learn anything via this exercise?

18 | P a g e
Appendix 1:

Here, I provide the mathematical equivalents for all the matrices for matrices.m. This is provided
so you can generate the complete matrices.m script. This may be useful as a direct comparison
between Matlab syntax and traditional mathematical formatting.

matrices.m will generate the following matrices in your workspace:

Part 1:
1 2 3 4 5
1 2 3 4
6 7 8 9 10
𝐴5,1 = 11 12 13 14 15 𝐴4,1 = [2 4 7 11]
3 7 14 25
16 17 18 19 20
[21 4 11 25 50
22 23 24 25]

5
𝐵4,2 = [10] 𝐵4,1 = [5 10 15 20]
15
20

2 3 6 3
𝐴2,1 = [ ] 𝐴2,2 = [ ]
5 8 8 4

Part 2:

2 6 10
𝐴2,3 = [ ] 𝐵2,3 = [ ]
−5 4 −3

1 2 3 39
𝐴3,1 = [1 3 2] 𝐵3,1 = [34]
3 2 1 26

2 4 6 0
𝐴3,2 = [4 5 6] 𝐵3,2 = [ 3]
7 8 9 6

1 2 3 0
𝐴3,3 = [4 5 6] 𝐵3,3 = [ 3]
7 8 9 0
19 | P a g e
Appendix 2:

The template of matrices.m:

% Optics 211
% Lab 3
% Prepared by Gregory R. Savich, PhD
% 2/16/2016
%
% This script is designed to fill the workspace with the matrices necessary
% to complete the in-class portion of lab 3. When the script is run via
% the command window, it will not yield any results or answers; however,
% the workspace will be filled with matrices. These matrices can be called
% up from the command window for further manipulation.
%
% Appendix 1 of lab 3 serves as a companion to this script and shows all
% the matrices generated here in traditional mathematical formatting.
%
% This script can be found in Appendix 2 of lab 3.

% Part 1 of 2 of lab 3

% 5x5 matrix for data manipulation


A51= ;

% 4x4 matrix for computing the inner product and finding determinant and
% inverse
A41= ;

% 1x4 and 4x1 matrices for evaluating the inner product and using transpose
% operator
B41= ;
B42= ;

% 2x2 Matrix (invertible)


A21= ;

% 2x2 Matrix (non-invertible)


A22= ;

% Part 2 of 2 of lab 3

% 2 equation, 2 unknown, linear system of equations with 1 solution


A23= ;
B23= ;

% 3 equation, 3 unknown, linear system with 1 solution


A31= ;
B31= ;

% 3 equation, 3 unknown, linear system with an infinite number of solutions


A32= ;
B32= ;

% 3 equation, 3 unknown, linear System with no solution


A33= ;
B33= ;

% End of script

20 | P a g e

You might also like