MATLAB Project PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 96

Laboratory Activity 1

MATLAB FUNDAMENTALS

Objective
The activity aims to familiarize students with the basic functionality of MATLAB as a
mathematical tool in solving simple arithmetic problems.
Intended Learning Outcomes (ILOs)
The students shall be able to

1. Identify and manipulate various MATLAB windows

2. Create a variable name

3. Perform fundamental operations on an array

Discussion
MATLAB is an abbreviation for “MATrix LABoratory”. MATLAB is developed and published
by MathWorks founded in 1984, a leading developer and supplier of technical computing software in
the world. Is a versatile piece of computer software with Linear Algebra capabilities as its core.

MATLAB is a numerical computing environment and programming language that allows you
for easy matrix manipulation, plotting of function and data, implementation and development of features
of MATLAB is that it has mathematical functions for linear algebra, statistic, Fourier analysis, filtering,
optimization, numerical integration, and solving ordinary differential equations.

MATLAB can be used for a range of applications, including signal processing and
communications, image and video processing, control systems, test and measurement, computational
finance, and computational biology. Most of its users are engineers and scientists in industry and
academia.

Resources
PC with MATLAB Software
Procedure
Starting MATLAB for Windows
You can start MATLAB by double clicking on the MATLAB icon that should be on the desktop
of your computer. This brings up the Desktop as shown in Figure 1.1 in its default layout of your
MATLAB Environment. Navigate the basic functionality of MATLAB window.

1
Figure 1-1: The default view of MATLAB

The desktop includes the following:


 Current Folder is used to access your files.
 Command Window is used to enter commands at the command line, indicated by the prompt
(>>).
 Workspace is used to explore data that you create or import from files.

Unlike the previous versions of MATLAB, the environment of the R2018a version it does not
show the Command History -used to view or rerun commands that you entered at the command line
and does not feature the start button. Instead, a ribbon-type menu which displays all available menu
items for a particular category is used.
Each of the windows of the default MATLAB environment is undockable. Just click on the pull
down icon to display the options for the window.

2
Working with MATLAB windows
1. The command window is located in the center pane of the default view of the MATI.AB screen,
as shown in Figure 1-1. The command window offers an environment similar to a scratch pad.
To type a command, the cursor is placed next to the command prompt (>>), as shown in Figure
1-1.

2. The <Enter> key is pressed once a command is typed, and the command is automatically
executed. However, only the last command is executed. Everything executed previously is
unchanged.

3. Several commands can-be typed in the same line by typing a comma between the commands.
Once the< Enter> key is pressed the commands are executed in order from left to right. When
you type a semicolon (;) at the end of the command the Command window output is suppressed.

4. As you enter commands, MATLAB saves a number of the most recent commands in a stack.
Previous commands saved on the stack can be viewed in the command history window. The
number of commands saved on the stacks varies, depending on the length of the commands and
other factors.

5. You can recall previously typed command pressing up- and down-arrow keys (↑) and (↓).Press
the arrow keys either at an empty command line or after you type the first few characters of a
command. When the command is displayed on the command prompt, it can also be edited if
needed and executed.

6. If a command is too long to fit in one line, it can be continued to the next line by typing three
periods … (or ellipsis) and pressing the <Enter> key. The continuation of the command is then
periods typed in the new line.

7. If MATLAB recognizes an error after you have pressed ENTER to execute a command, then
MATLAB responds with a beep and a message that helps define the error. You can recall the
command line and edit it as you would any computer text.

8. As you type the command you need to specify the input and output variable name. then
MATLAB adds the variable name in the workspace pane if you do not specify a output variable
name MATLAB uses variable ans, short for answer to store your calculation.
Variables names are case-sensitive. Only alphanumeric characters, and the underscore character
are allowed to be used as variable names.

9. The command isvarname determines whether a variable name is valid or not,

10. You can check the contents of the Workspace by using the whos command or by clicking on the
Desktop menu in the Menu bar and checking Workspace from the pull-down menu.

11. You can determine if a variable name is a built-in function by using which command, while
iskeyword command determines if it is a keyword.

12. If you end a statement with a semicolon, MATLAB performs the computation, but suppresses
the display of output in the Command Window.

3
Understanding the MATLAB Math Syntax
The MATLAB syntax is a set of rules that you use to tell MATLAB what to do. In order to
communicate with MATLAB, you must understand its language, which is essentially a form of math.

Using MATLAB as Calculator


MATLAB is a math-based language, so it pays to review the basic rules for telling MATLAB
how to perform basic math tasks.
a. + or plus() - Adds two numbers.
b. - or minus() - Subtracts two numbers.
c. * or times() - Multiplies two numbers.
d. / or rdivide() -Performs right division.
e. \ or Idivide() - Performs left division, which is also called "goes into"
f. ^ - Exponents
g. eps - Specifies the accuracy of the floating-point precision (epsilon), which defaults to
2.2204e-16.
h. i - Contains an imaginary number, which defaults to 0.0000 + 1.0000i.
i. Inf - Defines a value of infinity, which is any number divided by O, such as 1/0.
j. NaN - Specifies that the numerical result isn't defined (Not a Number).
k. pi - Contains the value of pi, which is 3.1416 when you view it onscreen. Internally, MATLAB
stores the value to 15 decimal places so that you're assured of accuracy.
l. sqrt() -provides the square root of an array
m. parenthesis and bracket () & [] -are the only allowed grouping symbol

HELP SYSTEM
All MATLAB functions have supporting documentation that includes examples and describes
the function Inputs, outputs, and calling syntax.
There are several ways to access this information from the command line:
1. Open the function documentation in a separate window using the doc command.
doc mean
2. Display function hints (the syntax portion of the function documentation) in the
Command Window by pausing after you type the open parentheses for the function input
arguments.
mean()
3. View an abbreviated text version of the function documentation in the Command
Window using the help command,
help mean- Access the complete product documentation by clicking the help icon.

Saving Your Workspace


Workspace variables do not persist after you exit MATLAB. Save your data for later use with
the
save command, save myfile.mat
Saving preserves the workspace In your current working folder in a compressed file with a –mat
extension, called an MAT-file.

Exiting from MATLAB

4
You can quit MATLAB at any time with one of the following:
 Select Exit MATLAB from the desktop File menu.
 Enter quit or exit at the Command Window prompt.

Note: Do not click on the close box in the top right corner of the MATLAB desktop. This does not allow
MATLAB to terminate properly and, on rare occasions, may cause problems with your computer
operating software

5
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS:

Task 1: Answer the following questions.


1. What is/are the use(s) of the workspace window?

2. Give at least two ways to change the layout of your windows.

3. Give the different ways to exit MATLAB properly.

4. What is the difference between docking and undocking windows?

5. What special character(s) is/are allowed to be used in assigning variable names?

6
6. Are the variable names a and A the same? Why?

7. How will you determine if the variable name(s) is/are built-in function(s) in MATLAB?

8. Give at least one way to determine all MATLAB functions supporting documentation that
includes examples and describes the function inputs, outputs, and calling syntax.

9. What is the difference between semi-colon syntax and colon syntax?

Task 2: Which of following names are allowed to be a variable name, a keyword or a built in function
in MATLAB? Write V if it Is allowed to be a variable name, K for keyword and B If It Is a built in
function.
1. test _______________________________________________________________________

2. if _______________________________________________________________________

3. sine _______________________________________________________________________

4. linear_matlab ________________________________________________________________

5. Thisisoneverylongnarnebutisitstjllallowed? ______________________________________

7
Task 3: Perform the Indicated operation using MATL4B syntax. Write the MATLAB syntax and output
on the space provided.

MATLAB SYNTAX MATLAB OUTPUT


5+3
a.
9−1
4
b. 23 −
5+3

52+1 3
c. +2
4−1 4

1 2
d. (4 ) (5 )
2 3

7
5+6( )−22
3
e. 1
2 2 4+2
( )((3)(6))
3

f. (√3 + 4) + 𝜋 2 −
1
√3 + √2𝜋 + (3 − 4)2
2

8
Laboratory Activity 2
MATRICES AND ARRAY

Objective
This activity aims to let the students understand matrices and arrays in MATLAB

Intended Learning Outcomes (ILOs)


The students shall be able to:

1. Generate arrays and matrices

2. Input matrices with the correct display format

3. Perform concatenation of matrices

4. Perform array indexing

Discussion

The MATLAB environment uses the term matrix to indicate a variable containing real or complex
numbers arranged in a two-dimensional grid. An array is, more generally, a vector, matrix, or higher
dimensional grid of numbers. All arrays in MATLAB are rectangular, in the sense that the component
vectors along any dimension are all the same length.

Resources
PC with MATLAB Software
Procedure
Part A. Generating and Deleting a matrix and an array
1. To create an array with several elements in a single row, type the elements and separate each
element with either a comma (J) or a space and enclose it with a square bracket. This type of
array is a row vector

Try and Verify!!!


>>a = [123]
a=
1 2 3

2. To create a matrix that has multiple rows, type the element for each row and separate these rows
with semicolons; then enclose the matrix with square brackets.

Try and Verify!!!

>>a = [1 2 3; 4 5 6; 7 8 9]

9
a=
1 2 3
4 5 6
7 8 9

3. Matlab has different functions that create different kinds of matrices. One way to create a matrix
is to use functions, such as ones, zeros, randn, and function will generate a matrix with all
elements equal to 1. The zeros on the other hand will generate a matrix with all elements equal
to O. The function rand a matrix with uniformly distributed elements while the randn function
generates normally distributed elements.

To generate a matrix of zeros type zeros. b) where a are the number of rows and b are the number
of columns or type zeros (x) where x is the order of the matrix for square matrices. The same
format is used for the ether commands.

Try and Verify!!!

>> zeros(1,5)
ans =
0 0 0 0 0

>> ones(3)
ans =
1 1 1
1 1 1
1 1 1

>> randn(1,2)
ans =
0.7172 1.6302

>> rand(1,3)
ans =
0.9649 0.1576 0.9706

4. Another function that will generate matrices are pascal and magic. The pascal function generates
symmetric matrices white the magic function will generate non- symmetric matrices. To create
symmetric matrices type pascal(x) where is the order of your matrix. Do the same to create nan-
symmetric matrices but using the magic function These functions generate square matrices only.

Try and Verify!!!

>> pascal(3)
ans =

1 1 1
1 2 3
1 3 6

10
>>𝑚𝑎𝑔𝑖𝑐(3)
ans =
8 1 6
3 5 7
4 9 2
5. An nxn Identity matrix is denoted by In. MATLAB has a command to generate In with the
syntax eye( ).

Try this and Verify!!!

eye(2) - displays a 2 x 2 identity matrix

eye(5) - displays a 5 x 5 identity matrix

𝐭 = 𝟏𝟎; eye(t) - displays a 10 x 10 identity matrix

eye(sizeA) - displays an identity matrix the same size as A

6. MATLAB has a command to build diagonal matrices when only the diagonal entries are
inputted. The command is diag(), and also works to “extract" a set of diagonal entries.

Try this and Verify!!!

A=
8 1 6

3 5 7

4 9 2

>> b = diag(A)

b=

11
>> 𝑐 = 𝑑𝑖𝑎𝑔(𝑑𝑖𝑎𝑔(𝐴))
c=

8 0 0

0 5 0

0 0 2
7. A matrix name can be reused. In such a case the "old" contents are lost.

8. To determine the matrix names that are in use, use the who command.

9. To delete a matrix, use the clear command, followed by a space and then the matrix name.

10. To determine the number of rows and columns in a matrix, use the size command.

Note: Notice that no brackets are displayed and that MATLAB has assigned this matrix the name ans.
Every matrix in MATLAB must have a name. If you do not assign a matrix name, then MATLAB assigns
it with ans which is the default variable name. Name each matrix with different variable names

If the matrix is quite large, the screen display will scroll too fast for you to see the matrix.

Part B. Display Formats

The format function controls the numeric format of the values displayed. The function affects
only how numbers are displayed, not how MATLAB software computes or saves them.

The different formats are format short, format long, format rat, format bank, format hex. the
default format in MATLAB is short.

Try this and Verify!!!

>>format short
>>𝑥 = [4/3 1.2345e − 6]
x=
1.3333 0.0000

>>format long e
>>𝑥 = [4/3 1.2345𝑒 − 6]
x=
1.333333333333333e+00 1.234500000000000e-06

>>format short e
>>x =[4/3 1.2345e-6)
x=
1.3333e+00 1.2345e-06

>>format rat
x = [4/3 1.2345e-61
x=

12
4/3 1/810045

>>format bank
x = [4/3 1.2345e-6]
x=
1.33 0.00

>>format hex
x = [4/3 1.2345e-6]
x=
3ff5555555555555 3eb4b6231abfd271

Part C. Concatenation
Concatenation is the process of joining arrays to make larger ones. A pair of square brackets [ ] is the
concatenation operator.
1. To concatenate horizontally use commas.
2. To concatenate vertically use semicolons.

Try and Verify!!!

a=
1 3
4 2

b=
1 1
1 2

>>𝐴 = [𝑎, 𝑏]
𝐴=
1 3 1 1
4 2 1 2

>>𝐵 = [𝑎; 𝑏]
𝐵=
1 3
4 2
1 1
1 2

13
Part D. Indexing
Every variable in MATLAB is an array that can hold many numbers. When you want to access
selected elements of an array, use indexing.

Try and Verify!!!

𝐴=
8 1 6
3 5 7
4 9 2

There are two ways to refer to a particular element in an array. The most common way is to specify row
and column subscripts
>> 𝐴(3,2)
𝑎𝑛𝑠 =
9
Another way is by the use of Linear Indexing where a single subscript that traverses down each column,
in order, to the desired element is used.
>>> 𝐴(6)
𝑎𝑛𝑠 =
9

To refer to multiple elements of an array, use the colon operator, which allows you to specify a range
of the form start:end.

>> 𝐴(3,2)
𝑎𝑛𝑠 =
6
7

>> 𝐴(2, : )
𝑎𝑛𝑠 =
3 5 7
The colon operator also allows you create an equally spaced vector of values using the more general
form start:step:end

>> 𝐵 = 𝑂: 10: 100


>> 𝐵 =

0 10 20 30 40 50 60 70 80 90 100

14
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS
Do as directed. Write all the syntax/commands and MATLAB output in the table for each activity.
use the rational format of MA TLAB unless stated otherwise.

Task 1: Write the syntax that will create the following matrices.

MATRIX MATLAB SYNTAX


1 1 1 0 0
1 1 1 0 0
1. 1 0 0 1 0
0 1 0 1 0
[0 0 1 1 1]
𝜋 𝜋 𝜋 𝜋 𝜋
1 1 1 1 1
2. [ ]
0 0 0 0 0
1 1 1 1 1

5 0 0
3. [0 5 0]
0 0 5

√2 √2 √2
4. [√2 √2 √2]
√2 √2 √2

2 0 0 0 0
0 2 0 0 0
5. [ ]
0 0 2 0 0
1 1 1 1 1

15
Task 2: Create a 3x 3 magic matrix A concatenate horizontally with a 3 x 3 pascal matrix B. Write
the syntax and output that will...
1. Extract the element in row 3 column 4
2. Extract the four corner elements
3. Extract column 3
4. Extract the diagonal
5. Create a diagonal matrix using the result in no. 4 as the diagonal.

MATLAB Syntax MATLAB Output


Concatenated Matrix A and B

1.

2.

3.

4.

5.

16
Task 3:
a) In MATLAB, enter the following matrices

√5 𝑖 2√3 4∗2 2/2


−3
𝐴= 4
0 1 𝐵 = [ 1/201 5 − 8.2 ]
1
4𝑖 −𝑖 ] 0.0001 (9 + 4)/3
[ −3

b) Using the matrrces in (a) and the proper MATLAB commands, display

b.1 𝑎21 , 𝑏32 , 𝑏12 , 𝑎22 simultaneously arranges in a single row.

b.2 row 1 of A, column 2 of A and row 3 of B separately.

c) Concatenate A and B horizontally and vertically if possible.

d) Display matrix B in long format and matrix A in rational format

e) Compare the new format of A and B to the original format, how do they differ?

MATLAB Syntax MATLAB Output


a.

b.1

b.2

c.

d.

e.

17
Laboratory Activity 3
MATRIX MANIPULATION

Objective
To be able to use MATLAB in manipulating matrices

Intended Learning Outcomes (ILOs)


The students should be able to:

1. Identify the different functions in MATLAB used in manipulating matrices

2. Manipulate matrices using MATLAB

Discussion
MATLAB functions syntax lists their input arguments inside parentheses and separated by
commas. For example,
>>ℎ𝑠 = sin(𝑝𝑖 ∗ (0: 5)/5)
ℎ𝑠 =
0 0.5878 0.9511 0.9511 0.5878 0.0000

Command syntax doesn't use parentheses, frequently doesn't place output in a variable, can't
return multiple variables, and handles only literal string inputs. For example

>>𝑑𝑖𝑠𝑝 𝑑𝑖𝑟𝑛𝑎𝑚𝑒

dirname

displays the literal string dirname

There are several command and function syntax in MATLAB that generate special matrices that
are used in mathematics such matrices were magic, pascal identity and diagonal matrices...
MATLAB also provides various function syntax to manipulate matrices. These functions syntax
will be useful in solving problems related to matrices.
Resources
PC with MATLAB Software
Procedure
The following are the function syntax that can be used to manipulate matrices:

Matrix Manipulation

Cat -Concatenate array


reshape -reshape array
Diag -diagonal matrices and diagonals of matrix
Tril -extract lower triangular part
Triu -extract upper triangular part
Fliplr -flip matrix in left/right direction
flipud -flip matrix in up/down direction
flipdim -flip matrix along specified dimension
rot90 -rotate matrix 90 degree
: -regularly spaced vector and index into matrix

18
find -find indices of non-zero elements
end -last index
size -gives the size of the matrix
sum -calculate the sum of the entry in the column of the matrix

Generating special matrices:

blkdiag - Construct block diagonal matrix from input arguments


eye - Identity matrix
linspace - Generate linearly spaced vectors
logspace - Generate logarithmically spaced vectors
ones - Create array of all ones
rand - Uniformly distributed pseudorandom numbers
magic - Create magic square matrix whose row, column and diagonal sum are equal
pascal - Create a matrix whose elements are based on pascal's triangle
zeros - Create array of all zeros
horzcat - Concatenate arrays horizontally
vertcat - Concatenate arrays vertically

Try and Verify!!! Write the MATLAB output for each command.
>> C=magic(3); D=pascal(3);
>>E=cat(1, C, D)
>>F=cat(2, C, D)
>>linspace(1,2,3)
>>vertcat(C, D)
>>horzcat(C, D)
>>blkdiag(C)
>>reshape(F,6,3)

19
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS:

For numbers 1-11: Generate a magic matrix A of order 5, a pascal matrix B of order 5, a linearly spaced
vector C with 5 elements from 10 to 20. Output should be in rational form.
1. Extract the main diagonal of A and B; also create a diagonal matrix whose diagonal is C.
2. Extract the diagonal that runs from lower left to upper right of A and B.
3. Concatenate these matrices A, B, and C horizontally and vertically if possible.
4. Concatenate matrix A and B by the third dimension.
5. Extract the lower and upper triangular matrices of A.
6. Reshape the matrix formed in number 3.
7. Rotate matrix B by 270 degrees.
8. Flip matrix A in the up/down direction.
9. Determine the. sum of the elements in the diagonal of A; also determine the sum of the elements
in each row and the sum of the elements in each column of A.
10. Flip matrix B from left to right.
11. Create an identity matrix with the same size of matrix

For nos. 12-15 Use MATLAB command/syntax to do the following. Output should be in rational form
12. Create a diagonal matrix with all entry in diagonal is 5.
13. Create a row vectors of odd numbers through 21.
14. Find a short MATLAB syntax that will create the given matrix

1 2 3 4 5 6 7
𝐴=[ ]
9 7 5 3 1 −1 −3
15. Create a 2 x 3 matrix of uniformly distributed pseudorandom numbers.
MATLAB Syntax MATLAB Output
1.

2.

20
3.

4.

5.

6.

7.

8.

9.

10.

11.

21
12.

13.

14.

15.

22
Laboratory Activity 4
MATRIX AND ARRAY OPERATIONS
Objective
To be able to use MATLAB in performing operations on matrices and arrays
Intended Learning Outcomes (ILOs)
The students should be able to:

1. Identify and differentiate the different MATLAB syntax for matrix and array operations
2. Perform array operations MATLAB syntax
3. Perform matrix operations using MATLAB syntax
Discussion
Matrix is a rectangular array of numbers denoted by:

m-by-n matrix
n columns

𝑎1,1 𝑎1,2 𝑎1,3 ⋯


𝑎𝑖,𝑗
𝑎2,1 𝑎2,2 𝑎2,3 ⋯
𝑚 [ ]
𝑎 𝑎3,2 𝑎3,3 ⋯
𝑟𝑜𝑤𝑠 3,1
⋮ ⋮ ⋮ ⋱

The dimension /order of a matrix with m rows and n columns is denoted by mxn.

MATRIX OPERATIONS

Addition of Matrices

The sum A+B of two m-by-n matrices A and B is calculated entry wise (𝐴 + 𝐵)𝑖𝑗 = 𝐴𝑖𝑗 +
𝐵𝑖𝑗 , where 1 is m and 1 S j S n.

If A and B are m x n matrices, we write A + (-) B as A — B and call this the difference
between A and B.

Scalar Multiplication

The scalar multiplication cA of a matrix A and a number c (also called a scalar) is given by
multiplying every entry of A by c: (𝑐𝐴)𝑖𝑗 = 𝑐 • 𝐴𝑖𝑗 .

Transpose
The transpose of an m-by-n matrix A is the n-by-m matrix 𝐴𝑇 (also denoted 𝐴𝑡𝑟 or 𝐴𝑇 ) formed by
turning rows into columns and vice versa: (𝐴𝑇 )𝑖,𝑗 = 𝐴𝑖,𝑗 .

Multiplication

Is defined only if the number of columns of the left matrix is the same as the number of rows of the
right matrix. If A is an m-by-n matrix and B is an n-by-p matrix, then their matrix product AB is the
matrix whose entries are given by the dot-product of the corresponding row of A and the corresponding
column of B:

23
𝑛
[𝐴𝐵]𝑖,𝑗 = 𝐴𝑖,𝑗 𝐵𝑖,𝑗 + 𝐴𝑖,2 𝐵2,𝑗 + 𝐴𝑖,𝑛 𝐵𝑛,𝑗 = ∑ 𝐴𝑖,𝑟 𝐵𝑟,𝑗
𝑟=1

Note:

BA may not be defined; this will take place if n*m.


a) If BA is defined, which means that m: n, then BA is p x p while AB is mx m; thus if m*P, AB
and BA are of different sizes.
b) b) If AB and BA are both of the same size, they may be equal
c) c) If AB and BA are both of the same size, they may be unequal

Array Operations:

Array operations work on corresponding elements of arrays with equal dimensions. For
vectors, matrices, and multidimensional arrays, both operands must be the same size. Each element in
the first input gets matched up with a similarly located element from the second input; evaluated
element by element.

Resources
PC with MATLAB Software

Procedure
MATRIX OPERATIONS IN MATLAB
The operations of addition, subtraction, and multiplication of matrices in MATLAB follow the
same definitions If A and B are mx n matrices that have been entered into MATLAB, then

1. The sum in MATLAB is computed by the command A+B


2. The difference by the command A-B
(Spaces can be used on either side of + or -.)

3. If A Is m x n and C is n x k, then the product of A and C in MATLAB must be written as A *C

4. In MATLAB, * must be specifically placed between the names of matrices to be multiplied.

5. In MATLAB, writing AC does not perform an implied multiplication. MATLAB considers AC


a new matrix name, and if AC has not been previously defined, an error will result from
entering it.

6. Scalar multiplication 5A denotes scalar multiplication in math language while 5*A is required
in MATLAB

7. In MATLAB the transpose operator (or symbol) is the single quotation mark, or prime, '.

24
Array Operations in MATLAB

Matrix operations follow the rules of linear algebra. By contrast, array operations execute
element by element operations and support multidimensional arrays. The period character (.)
distinguishes the array operations from the matrix operations. However, since the matrix and array
operations are the same for addition and subtraction, the character pairs .+ and .- are unnecessary.
a.∗ b multiplies each element of a by the respective element of b
a./b divides each element of a by the respective element of b
a.\b divides each element of b by the respective element of a
a. ^b raise each element of a by the respective b element
a.' array transpose (non-conjugated transpose)

Try and Verify!!!

>>𝒙 = [1 2 3]; 𝑦 = [4 5 6]
− x ′ ∗ y = 32
− x .∗ y = [4 10 18]

25
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS

1. In MATLAB enter the following matrices with rational format.

1 1/2 3
4 5/4 9/4
𝐴 = [1/3 1/4] 𝐵 = [5 −2] 𝐶=[ ] 𝐷 = [−1]
1 2 3
1/5 1/6 4

Using MATLAB commands compute the following expressions, if possible, using matrix
operations.
Given MATLAB Syntax MATLAB OUTPUT
1. Product of the transpose of
A and half of D.
2. Matrix B multiplied to the
transpose of the sum of A
and transpose of C
3. Six times of D subtracted
from transpose of twice C
multiplied to B,
4. Sum of the product of A
and transpose and the its
product of the transpose of
C and C.
5. Square of the product of
thrice A and B.

26
2. In MATLAB enter the following matrices with rational format.

1/2 3/4 1 + 3𝑖 −2 + 5𝑖
4 5/4 9/4
𝐴 = [ −1 1/5] 𝐵 = [5𝑖 −2 √2𝑖 ] 𝐶=[ ] 𝐷 = [ −1 𝑖−1 ]
1 4 − 4𝑖 √2 −1 −2 −3
0 −2 4+𝑖 2 − 3𝑖

Using MATLAB commands compute the following expressions, if possible, using array operations.
Given MATLAB Syntax MATLAB Output
1. Multiply A and D then add
the product to the
conjugated transpose of B.

2. Sum of A, non-conjugated
transpose of B, transpose of
the square of C and twice
D.

3. Six times of transpose of A


subtracted from thrice C
divided by B.

4. Divide C by the transpose


of A then add the result to
the matrix obtained when
the conjugated transpose of
D is divided by the
negative of B.

5. Product of A and B from


the subtracted product of C
and D.

27
−2 −1 0 3
3. Solve for x in the equation given: 𝐴 = [ 3 −4] 𝑎𝑛𝑑 𝐵 = [ 2 0]
1 2 −4 −1

Equation MATLAB Syntax MATLAB Output


1. 𝑥 = 3𝐴 − 2𝐵

2. 2𝑥 + 3𝐴 = 𝐵

3. 2𝐴 + 4𝐵 = −2𝑥

4. 2𝑥 = 2𝐴 − 𝐵

28
Laboratory Activity 5
SYSTEMS OF LINEAR EQUATIONS
MATRIX INVERSE AND MATRIX LEFT DIVISION
Objective
To be able to use MATLAB to solve system of linear equations using inverse of matrix and left
division
Intended Learning Outcomes (ILOs)
The students should be able to:
1. Determine the inverse of a matrix using the syntax inv and A^-1 in MATLAB
2. Solve system of linear equation using Inverse of a matrix
3. Solve system of linear equation using left division.
Discussion
System of m linear equations in n unknowns, 𝑥1 , 𝑥2 , 𝑥3 … . 𝑥𝑛 or a linear system, is a set of m linear
equations each In n unknowns.

𝑎11 𝑥1 + 𝑎12 𝑥2 + ⋯ + 𝑎1𝑛 𝑥𝑛 = 𝑏1


𝑎21 𝑥1 + 𝑎22 𝑥2 + ⋯ + 𝑎2𝑛 𝑥𝑛 = 𝑏2
⋮ ⋮ ⋮ ⋮
𝑎𝑚1 𝑥1 + 𝑎𝑚2 𝑥2 + ⋯ + 𝑎𝑚𝑛 𝑥𝑛 = 𝑏𝑚

If the linear system has no solution, it is said to be inconsistent: if it has a solution. it is called
consistent.

If 𝑏1 = 𝑏2 =. . . = 𝑏𝑖𝑗 = 0, then the system is called a homogeneous system𝑥1 , 𝑥2 , 𝑥3 … . 𝑥𝑛 =


0. is always a solution to a homogeneous system; it is called the trivial solution. A solution to a
homogeneous system in which not all of 𝑥1 , 𝑥2 … . 𝑥𝑛 are zero is called a nontrivial solution.

Inverse of a matrix

An n x n matrix A is called nonsingular, or invertible, if there exist n x n matrix B such that A


B = B A = In; such a B is called an inverse of A. Otherwise, A is called singular, or noninvertible.

If A is an n x n matrix, then the linear system Ax=b has the unique solution 𝑥 = 𝐴−1 𝑏.
Moreover, if b=0, then the unique solution to the homogeneous system Ax= 0 is x = 0
Resources
PC with MATLAB Software
Procedure

MATRIX INVERSE

MATLAB offers two approaches for finding the inverse of a matrix. we could raise A to the -1
Power with the code A^-I or we could use the built-in function inv.

MATLAB offers two approaches for finding the inverse of a matrix. we could raise A to the -1
Power with the code A^-I or we could use the built-in function inv.

29
Try and Verify!!!

𝑨=

𝟏 𝟏 𝟏
𝟏 𝟐 𝟑
𝟏 𝟑 𝟔

>>c=inv(A)

c=

3 −3 1
−3 5 −2
1 −2 1

Solution of System of Linear Equation by:

Matrix Inverse

Consider the given system of three equations with three unknowns:

3𝑥 + 2𝑦 − 𝑧 = 10
−𝑥+. 𝑦 + 2𝑧 = 5
𝑥 − 𝑦 − 𝑧 = −1

We can rewrite this system of equations by using the following matrices:

3 2 1 𝑥 10
𝐴 = [−1 3 2] 𝑥 = [𝑦] 𝐵=[ 5 ]
1 −1 −1 𝑧 −1

30
Using matrix multiplication, we can then rewrite the system of equations AX=B

In MATLAB, the matrix inverse is computed with the inv function, we can use the following
set of commands to solve this problem:

Input matrix A= [3 2 1; -1 3 2; 1 -1 -1] and B= [10; 5; -1]

Syntax: x= inv(A)*B

Verify!!!!

x= -2, 5, -6

Matrix Left Division

In MATLAB, we can use left division to solve the given problem. Thus, x=A\B

MATLAB is also capable of solving problems which are either over defined or under defined
using left division.

MATLAB uses a least squared approach to find the set of X values (which correspond to x, y,
z in our equations), which is the best match to the equations. The least squared approach minimizes the
absolute value of the difference between the calculated B values and the actual B values.

If your system of equations is under-defined MATLAB solves the problem by setting the first
variable equal to O, which effectively reduces the problem to two equations and two unknowns.

31
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS
Task 1: Given the following matrix and MATLAB syntax find the following. Results should be in
rational form.

1 −1 0 1 1 1
𝐴=[ 1 0 −1] 𝐵 = [ 3 5 4]
−6 2 3 3 6 5

a) (𝐴𝐵)−1

b) (𝐴𝑇 )−1

c) (𝐴)−2

d) (2𝐴)−1
MATLAB Syntax MATLAB Output
a)

b)

c)

d)

32
Task 2: solve the following systems of equations, using both matrix left division and the Inverse
method. Results should be in rational form.

−5 11 𝑥 − 2𝑦 + 1 = 4
−2𝑥 + 𝑦 = 3 − 𝑥 =𝑦
1.) 2.) 7 7 3.) 𝑥+𝑦+𝑧 = 2
𝑥 + 𝑦 = 10 2𝑦 = 7 + 5𝑥 3𝑥 + 3𝑦 + 3𝑧 = 14

3𝑥 + 𝑦 + 𝑧 + 𝑤 = 24
5𝑥 + 3𝑦 − 𝑧 = 0
𝑥 − 3𝑦 + 7𝑧 + 𝑤 = 12
4. ) 5.)3𝑥 + 2𝑦 + 𝑧 = 0
2𝑥 + 2𝑦 − 3𝑧 + 4𝑤 = 17
4𝑥 − 𝑦 + 3𝑧 = 0
𝑥+𝑦+𝑧+𝑤 =0

3𝑥1 + 4𝑥2 + 2𝑥3 − 𝑥4 + 𝑥5 + 7𝑥6 + 𝑥7 = 42


21 − 2𝑥2 + 3𝑥3 − 4𝑥4 + 5𝑥5 + 2𝑥6 + 8𝑥7 = 32
𝑥1 + 2𝑥2 + 3𝑥3 + 𝑥4 + 2𝑥5 + 4𝑥6 + 6𝑥7 = 12
6.) 5𝑥1 + 10𝑥2 + 4𝑥3 + 3𝑥4 + 9𝑥5 + 2𝑥6 + 𝑥7 = −5
3𝑥1 + 2𝑥2 − 2𝑥3 − 4𝑥4 − 5𝑥5 − 6𝑥6 + 7𝑥7 = 10
−2𝑥1 + 9𝑥2 + 𝑥3 − 3𝑥4 − 3𝑥5 + 5𝑥6 + 𝑥7 = 18
𝑥1 − 2𝑥2 − 8𝑥3 + 4𝑥4 + 2𝑥5 + 4𝑥6 + 5𝑥7 = 17

MATLAB Syntax MATLAB Output MATLAB Syntax MATLAB Output


(Matrix Inverse) (Matrix Solution Set) (Left Division) (Matrix and Solution
Set)
1.

2.

33
3.

4.

5.

6.

34
Laboratory Activity 6
SYSTEMS OF LINEAR EQUATIONS
LU - FACTORIZATION AND GAUSSIAN ELIMINATION

Objective:
To be able to use MATLAB to solve systems of linear equations using LU-factorization and
Gaussian elimination.
Intended Learning Outcomes (ILOs):
The students should be able to:

1. Determine the upper and lower triangular matrix of a given matrix using LU-factorization.

2. Generate an augmented matrix

3. Solve systems of linear equation using LU-factorization

4. Solve systems of linear equation using Gaussian elimination


Discussion:
Gaussian Elimination
The process of rewriting a system of linear equations in reduced row-echelon form (rref) that
usually involves a chain of equivalent systems, each of which is obtained by using row operations.

LU-Factorization

When U is an upper triangular matrix all of whose diagonal entries are different from zero, then
the linear system Ux = b can be solved without transforming the augmented matrix [U: b I to reduced
row echelon form or to row echelon form. The augmented matrix of such a system is given by:

𝑢11 𝑢12 𝑢13 … 𝑢1𝑛 | 𝑏1


0 𝑢22 𝑢23 … 𝑢2𝑛 | 𝑏2
0 0 𝑢33 … 𝑢3𝑛 | 𝑏3
⋮ ⋮ ⋮ … ⋮ | ⋮
0 0 0 … 𝑢𝑛𝑛 | 𝑏𝑛

The solution is obtained by the following algorithm:

𝑏𝑛 𝑏𝑛−1 − 𝑢𝑛−1𝑛 𝑥𝑛
𝑥𝑛 = … 𝑥𝑛−1 = ….
𝑢𝑛𝑛 𝑢𝑛−1𝑛−1

𝑗−1
𝑏𝑗 − ∑𝑘=𝑛 𝑢𝑗 𝑘 𝑥𝑘
𝑥𝑗 = , 𝑗 = 𝑛, 𝑛 − 1, … 2,1
𝑢𝑗𝑗

35
In a similar manner, if L is a lower triangular matrix all of whose diagonal entries are different
from zero, then the linear system Lx b can be solved by forward substitution' which consists of the
following procedure: The augmented matrix has the form:

ℓ11 0 0 … 0 | 𝑏1
ℓ21 ℓ22 0 … 0 | 𝑏2
ℓ31 ℓ32 ℓ33 … 0 | 𝑏3
⋮ ⋮ ⋮ … ⋮ | ⋮
[ℓ𝑛1 ℓ𝑛2 ℓ𝑛3 … ℓ𝑛𝑛 | 𝑏𝑛 ]

and the solution is given by:

𝑏1 𝑏2 − 𝑙21 𝑥1
𝑥1 = … 𝑥2 = ….
𝑙11 𝑙22

𝑗−1
𝑏𝑗 − ∑𝑘=𝑛 𝑙𝑗 𝑘 𝑥𝑘
𝑥𝑗 = , 𝑗 = 2, … 𝑛
𝑙𝑗𝑗
In this case we say that A has an LU-factorization or an LU-decomposition. The LU-factorization of a
matrix A can be used to efficiently solve a linear system Ax = b. Substituting LU fur A. we have (L U)
x=b
Resources:
PC with MATLAB Software

Procedure:
Gaussian Elimination
To solve for a given system of linear equations using MATLAB create an augmented matrix [a
b] were a are the coefficient matrix and b is the constant matrix. Use the function syntax rref() to reduce
the matrix to row echelon form.

Try and Verify!!!

Given:

𝑥 + 2𝑦 + 3𝑧 = 9
2𝑥 − 𝑦 + 𝑧 = 8
3𝑥 − 𝑧 = 3

The augmented matrix

1 2 3 9
[𝑎 𝑏] = [2 −1 1 8]
3 0 −1 3

Verify!!! 𝑥 = 2, 𝑦 = −1 𝑎𝑛𝑑 𝑧 = 3

36
LU-Factorization
lu(A) returns the matrix that contains the strictly lower triangular matrix L (the matrix without
its unit diagonal) and the upper triangular matrix u as submatrices. Thus, lu(A) returns the matrix U + L
- eye(size(A)), where L and U are defined as = lu(A). The matrix A must be square.

[L, U] = lu(A) returns an upper triangular matrix U and a matrix L, such that A = L*U. Here, L
is a product of the inverse of the permutation matrix and a lower triangular matrix.

To solve the given system of linear equations by LU-factorization using MATLAB. Create the
coefficient matrix then generate the lower(l) and upper (u) triangular matrix using = lu(A). Then solve
Ux = z and PLz = b using MATLAB syntax for matrix left division.

Try and Verify!!!

Given:

6𝑥1 − 2𝑥2 − 4𝑥3 + 4𝑥4 = 2


3𝑥1 − 3𝑥2 − 6𝑥3 + 𝑥4 = −4
{
−12𝑥1 + 8𝑥2 + 21𝑥3 − 8𝑥4 = 8
−6𝑥1 − 10𝑥3 + 7𝑥4 = −43

𝐴=

 6 2 4 4 
 3 3 6 1 

 12 8 21 8 
 
 6 0  10 7 

Verify!!!

𝐿=

 1 0 0 0
 1/ 2 1 0 0

 1 / 4 1 / 4 1 0
 
 1 / 2  1 / 2  6 / 7 1
𝑈=
 12 8 21 8 
 0  4  41 / 2 11 

 0 0 35 / 8  15 / 4
 
 0 0 0 16 / 7 

37
𝐿=

 1 0 0 0 
 1/ 2 1 0 0 

  1/ 4 1/ 4 1 0 
 
  1/ 2  1/ 2  6/7 1 

𝑈=

 12 8 21 8 
 0  4  41 / 2 11 

 0 0 35 / 8  15 / 4
 
 0 0 0 16 / 7 

And 𝑥1 = 4.5, 𝑥2 = 6.9, 𝑥3 = −1.2 𝑎𝑛𝑑 𝑥4 = −4

38
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS

ALL RESULTS SHOULD BE IN RATIONAL FORM.

A. Given the following matrices.

 1 1 1/ 5 
 2 2 
 2 8i 0 
3 4
 8√3 −1√−1 2 1 
 3 𝐶=  0
3 2
𝐴= 2
 2 𝐵=[ 3 7 2] 
 2 3 6 
 1 2 7i  𝜋 𝜋 5  1 1 2 3
1 
 2 3 4 

1. Determine reduced row-echelon form


2. Determine the lower and upper triangular matrices
Syntax Result-Reduced row echelon form
1.

Syntax Result(Lower Triangular) Result(Upper Triangular)

39
B. solve the given system of linear equations using the syntax rref and lu-factorization.

3𝑥 + 3𝑦 + 12𝑧 = 16 2𝑥 + 𝑦 − 𝑧 + 2𝑤 = −6
𝑥 + 𝑦 + 4𝑧 = 2 3𝑥 + 4𝑦 + 𝑤 = 1
1. 3.
2𝑥 + 5𝑦 + 20𝑧 = 10 𝑥 + 5𝑦 + 2𝑧 + 6𝑤 = −3
−𝑥 + 2𝑦 + 8𝑧 = 4 5𝑥 + 2𝑦 − 𝑧 − 𝑤 = 3

x  2 y  z  4w  11
3x  6 y  5 z  12 w  30 𝑥 + 𝑦 − 3𝑧 = 0
2. 4. 3𝑥 + 𝑦 − 𝑧 = 0
x  3 y  3z  2w  5 3𝑥 + 2𝑦 − 4𝑧 = 0
6 x  y  z  w  9

Syntax (Gaussian Results (rref of the Syntax Results (solution


Elimination) corresponding matrix; (LU-Factorization) matrix and the
also write the solution solution set)
to the system)
1.

2.

3.

4.

40
Laboratory Activity 7
PLOTTING LINEAR EQUATIONS
Objective:
To be able to use MATLAB to plot linear equations
Intended Learning Outcomes (ILOs):

The students should be able to:

1. Generate the required values for the unknown


2. Plot a given linear equation using MATLAB
Discussion :
A linear equation in variables 𝑥1 , 𝑥2 ,......𝑥𝑛 has the form 𝑎1 𝑥1 + 𝑎2 𝑥2 +......𝑎𝑛 𝑥𝑛 = 𝑏. The coefficients
𝑎1 , 𝑎2 ...... 𝑎𝑛 are real numbers, and the constant term b is a real number. The number 𝑎1 is the leading
coefficient, and xl is the leading variable.

A solution to linear equation is a sequence of n numbers 𝑠1 , 𝑠2 ..., 𝑠𝑛 which has the propety that the linear
equation is satisfied when 𝑥1 = 𝑠1 , 𝑥2 = 𝑠2,...,𝑥𝑛 = 𝑠𝑛 are Substituted in the linear equation.

The graph of the solution of the linear equation is a straight line.

Resources:
PC with MATLAB Software
Procedure:
The solutions of the given linear equations may be plotted in MATLAB. The most useful plot
for engineers is the x—y plot. A set of ordered pairs is used to identify points on the graph of a linear
equations the points are then connected by straight lines. The values of x and y may be measured or
calculated. Generally, the independent variable is given the name x and is plotted on the x -axis, and the
dependent variable is given the name y and is plotted on the Y -axis.

In MATLAB to plot a linear equation you need to defined


the values of x and y then you can use the plot functions. A graphics window automatically opens, which
MATLAB calls Figure 1. Slight variations in scaling of the plot may occur, depending on the size of the
graphics window.

≫ 𝑥 = [0,1,100];
≫ 𝑦 = 2 ∗ 𝑥 + 1;
>>plot(x,y)

41
You can add label the axes, add a title and background grid by the given command:
>> xlabel(‘title’)
>> ylabel(‘title’)
>> title(‘ ‘)
>> grid on

To add plots to an existing figure use hold


>> x=[0, 1, 100];
>> y=2*x-1;
>> plot(x,y);
>> hold on
>> x=[-1, 1, 100];
>> y2=2*x-1;
>> plot(x,y2,'r')
>> legend('grades','average')

Note: MATLAB overwrite the figure. To graph a new figure click plot in the menu bar then click new
figure.

42
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS
Given the following system of linear equations. Determine the solution set by graphing.
a. Plot each system of linear equations separately.
b. Create a title for each plot.
c. Create a label for-the x-axis and y-axis
d. Plot each equations using different color.
e. Create the legend for each equation
SYSTEM OF LINEAR MATLAB SYNTAX AND GRAPH
EQUATION SOLUTION SET

−24 − 8𝑥 = 12𝑦
1. 5 7
1 + 9 𝑦 = − 18 𝑥

𝑥−𝑦 1
16
=4
2.
𝑥−𝑦 =4

43
8𝑥 + 12𝑦 = 62
3. −11𝑥 − 4𝑦 = 8
−7𝑥 = 14

w  3y  0
2w  2 x  0
4.
2w  x  0
 6w  4 x  0

44
Laboratory Activity 8
DETERMINANTS USING ROW OPERATIONS

Objective
To be able to use MATLAB in solving by executing row operations and by using the det built-in
function.

Intended Learning Outcomes (ILOs)


The students shall be able to:
1. Perform elementary row operations in MATLAB.
2. Realize the effect of various row operations on the determinant of a given matrix.
3. Use the 𝑑𝑒𝑡 built in function in MATLAB to compute for the determinant of a matrix.

Discussion
A real number that is associated with square matrices is what we call the determinant of the matrix. By
definition, let 𝐴 = [𝑎𝑖𝑗 ] be an n x n matrix. The determinant function, denoted by 𝑑𝑒𝑡, is given by

det(𝐴) = ∑ ±𝑎1𝑗1 𝑎2𝑗2 . . . 𝑎𝑛𝑗𝑛 ,

Where the summation is over all permutations 𝑗1 𝑗2 … 𝑗𝑛 of the set S = {l, 2...,n} . The sign is taken as +
or— according to whether the permutation 𝑗1 𝑗2 … 𝑗𝑛 is even or odd. Aside from det (A), another
notation for the determinant of matrix A is |A|.

𝑎11 𝑎12
Consider a 2x2 matrix A =[𝑎 𝑎 ]. The determinant of A is determined by summing up the
21 22
terms q a2 and q a2 where the blanks in the subscript indicates permutations in the number of columns
forming the set S2 = {1, 2}, that is 12 and 21, hence

det(𝐴) = 𝑎11 𝑎22 − 𝑎12 𝑎21

It can be observed that the determinant of a 2x2 matrix is simply the difference of the products of the
elements in the upper left and lower right and lower left and upper right positions in the matrix.

𝑎11 𝑎12
det(𝐴) = [𝑎 𝑎22 ] = 𝑎11 𝑎22 − 𝑎12 𝑎21
21

𝑎11 𝑎12 𝑎13


Consider a 3x3 matrix 𝐴 = [𝑎21 𝑎22 𝑎23 ]. The determinant of A is determined by summing up the
𝑎31 𝑎32 𝑎33
six terms𝑎1 _𝑎2 _𝑎3 _, 𝑎1 _𝑎2 _𝑎3 , 𝑎1 _𝑎2 _𝑎3 , 𝑎1 _𝑎2 _𝑎3 , 𝑎1 _𝑎2 _𝑎3 , 𝑎𝑛𝑑 𝑎1 _𝑎2 _𝑎3 , where the blanks in the
subscript indicates permutations in the number of columns forming the set S3={l, 2, 3} , that
is 123, 231, 312, 132, 213 and 321.

det(𝐴) = 𝑎11 𝑎22 𝑎33 + 𝑎12 𝑎23 𝑎31 + 𝑎13 𝑎21 𝑎32 − 𝑎11 𝑎22 𝑎33 − 𝑎12 𝑎23 𝑎31 − 𝑎13 𝑎21 𝑎32

Likewise, as what is observed from the determinant of a 2x2 matrix, a simpler way of deriving the
determinant of a 3x3 matrix is by rewriting the first two columns of the matrix on the right side after the
third column and then making diagonals from upper left down and then summing up the products of the
elements in each diagonal. Make diagonals again from lower left up, getting the sum of the products of
the elements in the diagonals and then getting the difference of the first and second summations. That is,

45
𝑎11 𝑎12 𝑎13 𝑎11 𝑎12
𝑎
det(𝐴) = [ 21 𝑎22 𝑎23 ] 𝑎21 𝑎22
𝑎31 𝑎32 𝑎33 𝑎31 𝑎32

Determinants of matrices follow the following properties:


1. If A is a matrix, then 𝑑𝑒𝑡(𝐴) = 𝑑𝑒𝑡(𝐴𝑇 ).
2. If matrix B results from matrix A by interchanging two different rows or columns of A, then
3. If two rows or columns of A are equal, then 𝑑𝑒𝑡(𝐴) = 0
4. If a row or column of A consists entirely of zeros, then 𝑑𝑒𝑡(𝐴) = 0
5. If B is obtained from A by multiplying a row or column of A by a real number k, then
𝑑𝑒𝑡(𝐵) = 𝑘𝑑𝑒𝑡(𝐴).
6. If 𝐵 = [𝑏𝑖𝑗 ] is obtained from 𝐴 = [𝑎𝑖𝑗 ] by adding to each element of the rth row or column of
A, k times the corresponding element of the 𝑠𝑡ℎ row or column, 𝑟 ≠ 𝑠, of A, then
𝑑𝑒𝑡(𝐵) = 𝑑𝑒𝑡(𝐴).
7. If a matrix 𝐴 = [𝑎𝑖𝑗 ] is upper or lower triangular, then 𝑑𝑒𝑡(𝐴) = 𝑎11 𝑎22 … 𝑎𝑛𝑛 ; that is, the
determinant of a triangular matrix is the product of the elements on the main diagonal.

Resources
PC with MATLAB Software
Procedure
PART A: Built-ln Function for Determinants

1. Enter the following matrices in MATLAB.

 1 1 1 1
0  1 0 1 1 0 
 0 2 3 1 1   0 2 1 0 1 
 
𝐴=  1 1 0 3  3 𝐵=  1 1 0 1 2 
   
 1 1 2 2 1   1 2 0 0 1 
 0 0 0 0 1    1 0 0 0  1

  1 0  1 1 0
 0 0  1 0 1
 
𝐶 =  1  1 0 1 0
 
 1 0 1 0 3
 1 0 1 1 1

2. Using the built in function 𝑑𝑒𝑡 (name of matrix), one will be able to compute for the
determinant of the matrix that is; to get the determinant of matrix A, input 𝑑𝑒𝑡 (A) then press
enter, for matrix B, input 𝑑𝑒𝑡(𝐵) then press enter and so on. Note: It is necessary to enclose
the matrix name inside a parenthesis.

Verify the determinants of the three given matrices using this built-in function.

𝑑𝑒𝑡 (𝐴) = −10 𝑑𝑒𝑡 (𝐵) = 2 𝑑𝑒𝑡 (𝐶) = −5

46
PART B: Interchanging Rows

Preliminary Activity:

3 1 −2
Type the following matrix: 𝐷 = [2 −1 0 ]
0 −1 1
Recall: To interchange two rows (i.e. second and third rows) of D and name the new matrix R, type
𝑅 = 𝐷; 𝑅(𝐼, ∶) = 𝐷(2, ∶); 𝑅(2, ∶) = 𝐷(𝑙, : ) then press enter to return matrix R.

Using matrix A in PART A, execute the following commands:


1. Interchange the first and the third row of A and call the new matrix RI. The command is as
follows: 𝑅1 = 𝐴; 𝑅1(1, : ) = 𝐴(3, : ); 𝑅(3, : ) = 𝐴(1, : ).
Verify the determinant of RI by typing 𝑑𝑒𝑡(𝑅𝐼). 𝑑𝑒𝑡(𝑅𝐼) = 10
2. Interchange the second and fifth row of A and name the new matrix R2. Execute the command:
𝑅2 = 𝐴; 𝑅2(2, : ) = 𝐴(5, : ); 𝑅2(5, : ) = 𝐴(2, : ).
Verify the determinant of R2 by typing 𝑑𝑒𝑡(𝑅2). 𝑑𝑒𝑡(𝑅2) = 10
3. Interchange any other two rows of matrix A and call the matrix R3.
Find determinant of RI by typing 𝑑𝑒𝑡(𝑅3). 𝑑𝑒𝑡(𝑅3) = _______

What conjecture can you make from your observations of the values of the determinants obtained after
interchanging rows of a matrix?
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________
PART C: Multi I in a Row by a Scalar k

Preliminary Activity:

Using Matrix D in part B, to multiply the ith row of D by a scalar k and call the new matrix R, type
𝑅 = 𝐷; 𝑅(𝑖, : ) = 𝑘 ∗ 𝐷(𝑖, : ) hence, if we want to multiply the second row by 4, type in the command
prompt 𝑅 = 𝐷; 𝑅(3, : ) = 4 ∗ 𝐷(3, : )then press enter to return the new matrix R.

Using Matrix A, B and C in Part A,

1. Multiply the first row of A by 3 and call the new matrix R1.
Verify that 𝑑𝑒𝑡(𝑅1) = −24.

2. Multiply the third row of B by 5 and call the new matrix R2.
Verify that 𝑑𝑒𝑡(𝑅2) = 10.

3. Multiply any row of C by any scalar and call the new matrix R3.
Find the determinant of R1. 𝑑𝑒𝑡(𝑅3) = _______.

What conjecture can you make from your observations of the values of the determinants obtained after
multiplying a row of the matrix by a scalar?
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

47
PART D: Adding a Multiple of the ith Row to the jth Column

Preliminary Activity:

Using Matrix D in Part B, to add a multiple of the ith row (k times ith row) to the jth row Of D type:
R=D;R(j,:)=D(j,:)+k*D(i,:), hence, if one wants to add to the first row of D twice of the second row,
enter the command R=D;R(1,:)=D(1,:)+2*D(2,:).

Using Matrix A in Part A, perform the following.

1. Multiply the first row of A by 3 and add it to the second row of A, call the new matrix R1.
Verify that 𝑑𝑒𝑡(𝑅𝐼) = 8.
2. Multiply the third row of A by -5 and add it to the fourth row of A and call the new matrix R2.
Verify that 𝑑𝑒𝑡(𝑅2) = 8
3. Repeat the experiment using different rows of A. That is multiply a row in A by a scalar, then
add it to any other row of A and call the new matrix R3. What is 𝑑𝑒𝑡(𝑅3)?________.

What conjecture can you make from your observations of the values of the determinants obtained after
adding a scalar multiple of an 𝑖𝑡ℎ row to a 𝑗𝑡ℎ row of a matrix?
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

PART E: Determinants of Matrix Products


Using Matrices A, B and C in Part A, perform the following:
1. Obtain the determinant of the product of A and B by typing 𝑑𝑒𝑡(𝐴 ∗ 𝐵).
Verify that 𝑑𝑒𝑡(𝐴 ∗ 𝐵) = −16.
2. Obtain the determinant of the product of B and A by typing 𝑑𝑒𝑡(𝐵 ∗ 𝐴).
Verify that 𝑑𝑒𝑡(𝐵 ∗ 𝐴) = −16.
3. Obtain the determinant of the product of A and C by typing 𝑑𝑒𝑡(𝐴 ∗ 𝐶).
Verify that 𝑑𝑒𝑡(𝐴 ∗ 𝐶) = 40.
4. Obtain the determinant of the product of C and A by typing 𝑑𝑒𝑡(𝐶 ∗ 𝐴).
Verify that 𝑑𝑒𝑡(𝐶 ∗ 𝐴) = 40.
5. Obtain the determinant of the product of C and B by typing 𝑑𝑒𝑡(𝐶 ∗ 𝐵).
Verify that 𝑑𝑒𝑡(𝐶 ∗ 𝐵) = −10.
6. Obtain the determinant of the product of B and C by typing 𝑑𝑒𝑡(𝐵 ∗ 𝐶).
Verify that 𝑑𝑒𝑡(𝐵 ∗ 𝐶) = −10.

What conjecture can you make from your observations of the values of the determinants of
products of two different matrices?
____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________
7. Find the determinant of A3 by typing 𝑑𝑒𝑡(𝐴^3).
Verify that 𝑑𝑒𝑡(𝐴^3) = −512.
8. Find the determinant and B2 by typing 𝑑𝑒𝑡(𝐵^2).
9. Verify that 𝑑𝑒𝑡(𝐵^2) = 4.

48
What conjecture can you make from your observations of the values of the determinants of
matrix products of the form 𝐴𝑛 ?
____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________

PART F: Determinants of Scalar Multiples of A and Matrix Inverses


Using Matrices A, B and C in Part A, execute the following commands:
1. Get the determinant of three times Matrix A by typing.
Verify that 𝑑𝑒𝑡(3 ∗ 𝐴) = −24.
2. Get the determinant of negative two times Matrix B by typing 𝑑𝑒𝑡(−2 ∗ 𝐵).
Verify that 𝑑𝑒𝑡(−2 ∗ 𝐵) = −4.
What conjecture can you make from your observation of the values of the determinants of
scalar multiples of matrices?
____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________

3. Obtain the determinant of the matrix inverse of A by typing det(inv(A)) or det(A^-1).


Verify that 𝑑𝑒𝑡(𝑖𝑛𝑣(𝐴)) = −0.1250.
4. 4. Obtain the determinant of the matrix inverse of C by typing det(inv(C)) or det(C^-1).
Verify that 𝑑𝑒𝑡(𝑖𝑛𝑣(𝐶)) = −0.2000.
PART G: Determinants of Triangular Matrices

Using elementary row operations, find the determinant of the given matrix. Track the changes that are
happening with the determinant for each row operation performed.

4 3 2
1. Input the matrix 𝐴 = [3 −2 5]
2 4 6
1
2. Multiply row 3 by .
2
1
Not: ≫ 𝑀1 = 𝐴; 𝑀1(3, : ) = (2) ∗ 𝐴(3, : ) det(𝐴) = 2det(𝑀1)
𝑀1 =
4 3 2
3 −2 5
1 2 3

3. Interchange rows 1 and 3.

≫ 𝑀2 = 𝑀1; 𝑀2(1, : ) = 𝑀1(3, : ); 𝑀2(3, : ) = 𝑀1(1, : )


𝑀2 =
1 2 3
3 −2 5
4 3 2

49
4. Zero out below the 𝑎11 on 𝑀2 by
a. obtaining a new row 2 multiplying -3 to row 1 and then adding row 2 ; and
b. obtaining a new row 3 multiplying -4 to row 1 and then adding row 3.

≫ 𝑀3 = 𝑀2; 𝑀3(2, : ) = −3 ∗ 𝑀2(1, : ) + 𝑀2(2, : ); 𝑀3(3, : ) = −4 ∗ 𝑀2(1, : ) + 𝑀2(3, : )


𝑀3 =
1 2 3
0 −8 −4
0 −5 −10
Note: 𝑑𝑒𝑡(𝐴) = (−1)(2)𝑑𝑒𝑡(𝑀3), operations between rows does not change the determinant of the
matrix.
5
5. Zero out below the 𝑎22 entry on M3 by multiplying on 𝑀3 − 8 on row 2 and then adding row
3.
≫ 𝑀4
𝑀4 =
1 2 3
0 8 4
0 0  15 / 2

Note: 𝑑𝑒𝑡(𝐴) = (−1)(2)𝑑𝑒𝑡(𝑀4), operations between rows does not change the determinant of the
matrix.
6. Compute for the determinant of the upper triangular matrix which is just the product of the
15
elements in the main diagonal, hence 𝑑𝑒𝑡(𝑀4) = (1)(−8) (− 2 ) = 60
7. The determinant now of A is given by 𝑑𝑒𝑡(𝐴) = (−1)(2)𝑑𝑒𝑡(𝑀4) = (−2)(60) = −120

*You can check by using the 𝑑𝑒𝑡() built-in function.

50
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS:

TASK 1: Using elementary row operations, reduce to following matrices to triangular matrices to obtain
their determinants. Keep track by hand the changes in the determinant as you perform elementary row
operations. Write the correct syntax necessary to execute the commands. Use RATIONAL FORMAT.

2 1 3
𝐴 = [1 3 2] ; |𝐴| = _________
3 2 1
Track the changes in the determinant (by hand) Write the syntax, the resulting triangular
matrix and its determinant.

51
0 1 3  2
 2 1 1 1 
b. 𝐴 = 
2 0 1 2
 
1 0 0 1
Track the changes in the determinant (by hand) Write the syntax, resulting triangular
matrix and its determinant.

52
TASK 2: Use the 𝒅𝒆𝒕() built-in function to find the determinants of the following matrices. Write
the resulting matrix for c to e.

1 −1 1
a. 𝐴 = [ 1 1 −1] ; det 𝐴 = _______
−1 1 1

1 2 3 4
2 3 4 5
b. 𝐴 =  ; det 𝐴 = _______
3 4 5 6
 
4 5 6 7

2 3 0
c. 𝑀1 = 5 ∗ 𝑒𝑦𝑒(𝑠𝑖𝑧𝑒(𝐴)) − 𝐴, 𝑤ℎ𝑒𝑟𝑒 𝐴 = [4 1 0] ; 𝑀1 = det(𝑀1) = ______
0 0 5
2 1 1
d. 𝑀2 = (3 ∗ 𝑒𝑦𝑒(𝑠𝑖𝑧𝑒(𝐴)) − 𝐴) , 𝑤ℎ𝑒𝑟𝑒 𝐴 = [ ] ; 𝑀2 = det(𝑀2) = ______
5 2
1 1 0
e. 𝑀3 = 𝑡𝑟𝑎𝑛𝑠𝑝𝑜𝑠𝑒(𝐴) ∗ 𝐴, 𝑤ℎ𝑒𝑟𝑒 𝐴 = [0 1 0] ; 𝑀3 = det(𝑀3) = ______
1 0 1

TASK 3: Determine a positive integer t so that

5 2
det(𝑡 ∗ 𝑒𝑦𝑒(𝑠𝑖𝑧𝑒(𝐴)) − 𝐴) = 0, 𝑤ℎ𝑒𝑟𝑒 𝐴 = [ ]
−1 2

Solve for t manually and write your solution here:

Verify using Matlab if the value obtained by hand satisfies the given equation above, Write the syntax
below.

53
Laboratory Activity 9
PROPERTIES AND APPLICATIONS OF DETERMINANTS

Objective
To understand the different properties and applications of determinants.

Intended Learning Outcomes (ILOs)


The students shall be able to:
1. Find the determinant of a matrix product and a scalar multiple of a matrix.
2. Find the determinant of an inverse matrix and recognize equivalent conditions of a
nonsingular matrix.
3. Find the determinant of the transpose of a matrix.
4. Find the adjoint of a matrix and use it to find the inverse of the matrix,
5. Use Cramer's Rule to solve a system of n linear equations in n variables.
6. Use determinants to find area, volume, and the equations of lines and planes.
Discussion

Determinants of matrices are governed by the following properties:


1. If A and B are square matrices of order n, then 𝑑𝑒𝑡(𝐴𝐵) = det(𝐴) det(𝐵).
2. If A is a square matrix of order n and c is a scalar, then 𝑑𝑒𝑡(𝑐𝐴) = 𝑐 𝑛 𝑑𝑒𝑡(𝐴).
3. If A square matrix A is invertible (nonsingular) if and only if 𝑑𝑒𝑡(𝐴) ≠ 0.
4. If A is a square matrix, then 𝑑𝑒𝑡(𝐴) = 𝑑𝑒𝑡(𝐴𝑇 ).

THE ADJOINT OF A MATRIX

Recall that the corresponding cofactor matrix C of an nth order square matrix A is given by

C 11 C  C 
 
12 1n

C C  C
𝐶 =  21 22 2n
where the cofactor 𝐶𝑖𝑗 of each element is obtained by multiplying
    
 
C n1 C n2
 C nn

(−1)𝑖+𝑗 to the determinant of the minor 𝑀𝑖𝑗 of that element. The adjoint pf matrix A denoted by adj(A)
is the transpose of the Cofactor Matrix of A, that is

C 11 C  C 
 
12 1n

C C  C
𝐴𝑑𝑗(𝐴) = 𝐶 =  21
𝑇 22 2n
    
 
C n1 C n2
 C nn

54
The adjoint of matrix A is used to obtain the inverse of A. If A is an nxn invertible matrix, then
1
𝐴−1 = 𝐴𝑑𝑗(𝐴)
det(𝐴)
CRAMER'S RULE
Named after Gabriel Cramer (1704-1752), is a method on solving for the solution to systems of n linear
𝑎 𝑥 + 𝑎12 𝑥2 = 𝑏1
equations with n unknowns by using determinants. Consider the system{ 11 1 ,
𝑎21 𝑥1 + 𝑎22 𝑥2 = 𝑏2
𝑏 𝑎12 𝑎 𝑏1
| 1 | | 11 |
𝑏2 𝑎22 𝑎21 𝑏2
the solution is given by 𝑥1 = 𝑎11 𝑎12 , 𝑥2 = 𝑎11 𝑎12 , 𝑎11 𝑎22 − 𝑎21 𝑎12 ≠ 0. In general,
|𝑎 | |𝑎 |
21 𝑎22 21 𝑎22
if a system of linear equations in n variables has a coefficient matrix A with a nonzero determinant, then
the solution of the system is
(𝐴1 ) (𝐴2 ) (𝐴𝑖 )
𝑥1 = det , 𝑥2 = det ,……,𝑥𝑛 = det
det(𝐴) det(𝐴) det(𝐴)
Where the ith column of Ai is the column of constants in the system of equations.

AREA, VOLUME, AND EQUATIONS OF LINES AND PLANES

Determinants can also be applied in getting certain geometric quantities and equations.
a. The area of a triangle with vertices (𝑥1 , 𝑦1 ), (𝑥2 , 𝑦2 ), 𝑎𝑛𝑑 (𝑥3 , 𝑦3 ) is
1 𝑥1 𝑦1 1
𝐴𝑟𝑒𝑎 = ± det [𝑥2 𝑦2 1]
2 𝑥3 𝑦3 1
Where the sign ± is chosen to give a positive area.
𝑥1 𝑦1 1
b. Three points 1 , 𝑦1(𝑥 ), (𝑥 ),
2 , 𝑦2 𝑎𝑛𝑑 (𝑥3 , 𝑦3 are collinear if and only if 𝑑𝑒𝑡 = [ 2 𝑦2 1] = 0.
) 𝑥
𝑥3 𝑦3 1
c. The equation of the line passing through the distinct points (𝑥1 , 𝑦1 ), 𝑎𝑛𝑑 (𝑥2 , 𝑦2 ), is given by
𝑥1 𝑦1 1
det [𝑥2 𝑦2 1] = 0.
𝑥3 𝑦3 1
d. The volume of a tetrahedron with vertices
(𝑥1 , 𝑦1 , 𝑧1 ), (𝑥2 , 𝑦2 , 𝑧2 ), (𝑥3 , 𝑦3 , 𝑧3 )𝑎𝑛𝑑(𝑥4 , 𝑦4 , 𝑧4 ) is
x y z 1 
 1 1 1

1 x y z 2
1 
𝑉𝑜𝑙𝑢𝑚𝑒 = ± 𝑑𝑒𝑡  2 2

6 y z
 x3 3 3
1 
 1 
 x 4 y z 4 4 
Where the sign ± is chosen to give a positive volume.
e. Four points (𝑥1 , 𝑦1 ), (𝑥2 , 𝑦2 ), (𝑥3 , 𝑦3 ), 𝑎𝑛𝑑 (𝑥4 , 𝑦4 )are coplanar is and only if
x y z 1
 1 1 1

x y z 2
1
det  2 2
 =0
 x3 y 3 z 3
1
 1 
 x4 y 4 z 4 

55
f. An equation of the plane passing through the distinct points
x y z 1
 1 1 1

x y z 2
1
(𝑥1 , 𝑦1 ), (𝑥2 , 𝑦2 ), 𝑎𝑛𝑑 (𝑥3 , 𝑦3 )is given by det  2 2
 = 0.
 x3 y
3 z 3
1
 1 
 x4 y
4 z 4 
Resources
PC with MATLAB Software
Procedure
Part 1: Enter the following matrices in MATLAB and do what is indicated:
3 2 4 0 4 2 1 0
 1 1 2 1 1 1 2  1
a. 𝐴 =  ; 𝐵= 
0 0 3 1 0 0 2 1
   
 1 1 1 0  1 0 0 0
Verify that 𝑑𝑒𝑡(𝐴) = 𝑑𝑒𝑡𝐴𝑑𝑒𝑡𝐵. Type in MATLAB, 𝑑𝑒𝑡(𝐴) ∗ 𝑑𝑒𝑡(𝐵) 𝑎𝑛𝑑 𝑑𝑒𝑡(𝐴 ∗ 𝐵). What
do you observe?
____________________________________________________________________________
____________________________________________________________________________
40 25 10
b. [30 5 20]. Verify that det(𝑐𝐴) = 𝑐 𝑛 det(𝐴) by getting the value of c, n and the matrix A
15 35 45
manually. Then using these values in MATLAB, obtain the given matrix.
If n is the degree of the matrix, from the given, what is n? ______________________.
What scalar c can you factor out from the given matrix? _______________________.
After factoring out c, what now is the form of matrix A?

Input the correct syntax for 𝑑𝑒𝑡(𝑐𝐴) 𝑎𝑛𝑑 𝑐 𝑛 𝑑𝑒𝑡(𝐴) in MATLAB, What do you observe?
____________________________________________________________________________
___________________________________________________________________________.
−1 1 1 −1 3 4 3 −2
c. 𝐴 = [ ]; 𝐵 = [ ]; 𝐶 = [ ]; 𝐷 = [ ]
2 0 −2 0 2 2 1 1
Type the following commands in MATLAB, 𝑑𝑒𝑡(𝐴), 𝑑𝑒𝑡(𝐵), 𝑑𝑒𝑡(𝐴) + 𝑑𝑒𝑡(𝐵) 𝑎𝑛𝑑 𝑑𝑒𝑡(𝐴 + 𝐵).
Type the following commands in MATLAB, 𝑑𝑒𝑡(𝐶), 𝑑𝑒𝑡(𝐷), 𝑑𝑒𝑡(𝐶) + 𝑑𝑒𝑡(𝐷) 𝑎𝑛𝑑 𝑑𝑒𝑡(𝐶 + 𝐷).
What conjecture can you make about the determinants of a matrix sum?
________________________________________________________________________________
_______________________________________________________________________________.

d. 𝐴 = [𝑜𝑛𝑒𝑠(3,2) 𝑧𝑒𝑟𝑜𝑠(3,1)]
𝐵 = [𝑜𝑛𝑒𝑠(2,3); 𝑧𝑒𝑟𝑜𝑠(1,3)]
Gives a characteristic of B.
_____________________________________________________.
Enter det(𝐴) 𝑎𝑛𝑑 det(𝐵) 𝑖𝑛 𝑀𝐴𝑇𝐿𝐴𝐵. What do you observe?__________________________.
Make a conjecture regarding this observation about determinants of matrices having such
characteristics.
____________________________________________________________________________
___________________________________________________________________________.

56
 0.8 0.2  0.6 0.1
 1.2 0.6 0.6 0 
e. 𝐴 =  . det(𝐴) = ________________. Is A nonsingulat?__________.
 0.7  0.3  0.3 0 
 
 0.2  0.3  0.3 0 
3 2 1
4 3
−4
2 1
f. 𝐴= 3
1 3
det(𝐴) = ____________________. det(𝐴𝑇) = ________________________
1 1 3
[− 4 3 4 ]

PART 2. Locate the m-file 𝐜𝐨𝐟𝐚𝐜𝐭𝐨𝐫. 𝐦 in the current folder window. With this, the syntax
cofactor(A) can now be easily used to determine the cofactor matrix of a given matrix A.

2 −1 0
a. Input the matrix 𝐴 = [3 −2 1]. Type in MATLAB the following commands.
5 −4 2
>> cofactor(A)

>>

What does it do? _____________________________________________________________.


>>cofactor(A,2,3)

>>

What does it do? _____________________________________________________________.

b. Another way of solving the determinant of a matrix is by using Expansion by Cofactors.


Expansion by Cofactors gives the determinant by as:
det 𝐴 = 𝑎𝑖1 𝐶𝑖1 + 𝑎𝑖2 𝐶𝑖2 + 𝑎𝑖3 𝐶𝑖3 + ⋯ + 𝑎𝑖𝑛 𝐶𝑖𝑛 (𝑒𝑥𝑝𝑎𝑛𝑑𝑖𝑛𝑔 𝑎𝑏𝑜𝑢𝑡 𝑎𝑛 𝑖𝑡ℎ 𝑟𝑜𝑤)
det 𝐴 = 𝑎1𝑗 𝐶1𝑗 + 𝑎2𝑗 𝐶2𝑗 + 𝑎3𝑗 𝐶3𝑗 + ⋯ + 𝑎𝑚𝑗 𝐶𝑚𝑗 (𝑒𝑥𝑝𝑎𝑛𝑑𝑖𝑛𝑔 𝑎𝑏𝑜𝑢𝑡 𝑎 𝑗𝑡ℎ 𝑐𝑜𝑙𝑢𝑚𝑛)

Let us use expansion by cofactors in solving for the determinant of matrix A.


Say we want to expand about the third row. The equation now that we have to follow is
det 𝐴 = 𝑎31 𝐶31 + 𝑎32 𝐶32 + 𝑎33 𝐶33 which can be written in MATLAB as
>>>>detA=(A(3,1)*cofactor(A,3,1))-(A(3,2)*cofactor(A,3,2))+(A(3,3)*cofactor(A,3,3))

detA =

53
You can check using the det( ) built in function.

Try expanding about the second row of A.


What is the equation to solve for detA? ____________________________________________.
What is the MATLAB syntax for the equation in the previous question?
___________________________________________________________________________.
What is the value of the determinant of A by using expansion about Row 2? ______________.

57
PART 3. The inverse of a matrix A can be obtained in MATLAB as inv(A) or AA-I. An alternative
approach is to solve for the inverse of A by computing for the adjoint of A and dividing it by the
determinant of A. The adjoint of A is just the transpose of the cofactor matrix of A, that is

>>adjointA = (cofactor(A))
>>inverseA = adjoint/det(A)
What should be the condition for the inverse of a matrix to exist? Why?
__________________________________________________________________________________.

By using these syntax, obtain the adjoint and inverse of the following matrices:

1 0 3
a. 𝑇 = [0 −1 2] AdjointT=__________________ InverseT=______________________
2 1 0
0 2 −1
b. 𝑌 = [3 −2 1 ] AdjointY=__________________ InverseY=______________________
3 2 −1

PART 4.

a. Use determinants to obtain the area of a triangle whose vertices are at the points (1,5), (-2,7) and
(4,-4),
We solve this in MATLAB by constructing a 3x3 matrix whose fist column are the x-coordinates,
the second column are the y-coordinates and the third column are all 1.

>> Triangle = [1 5 1; -2 7 1; 4 -4 1]

>> Area=(1/2)*det(Triangle)

>>10.5

b. In MATLAB, you can put variables as elements in a matrix by using the syms command.

Use determinants to obtain the equation of a plane passing through (1,1,1), and (-2, -2,0).
Verify the following syntax
>>syms x y z
>>equation=det([x y z 1; 1 1 1 1; -3 2-1 1; -2-2 0 1]
>>

PART 5. CRAMER'S RULE

−2𝑥1 + 3𝑥2 − 𝑥3 = 1
To determine the solution of the system { 𝑥1 + 2𝑥2 − 𝑥3 = 4 , enter in MATLAB the coefficient
−2𝑥1 − 𝑥2 + 𝑥3 = −3
matrix A and the constant matrix b.
>>A=[-2 3 -1; 1 2 -1; -2 -1 3]; b=[1; 4; -3];
Obtain the determinant of A since det(A) should not be zero.
>>det(A)
ans
= -16

58
To obtain xl, get A1 by replacing the first row in A with the constant matrix b, Get the determinant of
A1 and then divide it by the determinant of A, that is
>>A1 = [b A(: ,2)A(: 3)]
A1 =
1 3 −1
4 2 −1
−3 −1 3
>>x1 = det(𝐴1)/ det(𝐴)
x1 =
1.5000
the values of x2 and x3 can be obtained in the same manner.

59
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS:

TASK1. Create the following matrices using proper concatenations and find the determinant of
each,

a. A 4x4 matrix whose elements in the first three columns are all 3 and the elements of the last column
are all 0. Find its determinant.
>>

b. A 4x4 matrix whose second to fourth row is comprised of a magic(3) matrix and whose first row
and fourth column has elements that are all 0 . Find its determinant.
>>

c. A 3x3 matrix whose elements in the first column and second column are the same. Find its
determinant.
>>

d. A 3x3 matrix whose elements in the third row are thrice the elements in the first row. Find its
determinant.
>>

Observing from the results of this task, what are the conditions that will yield zero determinants?
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________.

60
TASK 2. Write the correct MATLAB syntax in solving the following.

𝑡−1 0 1
a. Find all values of t for which | −2 𝑡 + 2 −1 | is singular.
0 0 𝑡+1
Note: To know how to find the roots of a polynomial equation, type help roots.
>>

𝑎+𝑏 𝑎 𝑎
b. Verify the equation | 𝑎 𝑎+𝑏 𝑎 | = 𝑏 3 (3𝑎 + 𝑏)𝑏𝑦 𝑢𝑠𝑖𝑛𝑔 𝑖) the det command and ii)
𝑎 𝑎 𝑎+𝑏
by assigning values for a and b.
>>

6 5 1 1
2 4 3 5
c. Given 𝐴 = . Find |𝐴|, |𝐴𝑇 |, |𝐴2 |, |2𝐴|, 𝑎𝑛𝑑|𝐴−1 |.
6 1 4 2
[ 2 2 1 3 ]
>>

61
TASK 3.
a. Use the cofactor routine to compute the cofactor of the elements in the second row of
1 5 0
𝐴 = [2 −1 3]
3 2 1
>>

1 2 0 0
2 1 2 0
b. Use Expansion by Cofactors to evaluate the determinant of 𝐴 = by
0 2 1 2
[ 0 0 2  1]
expanding about
i. The first column ii. The third row
>> >>

iii. Is A a singular or non-singular matrix? Can we obtain its inverse? If yes, what is 𝐴−1 using
adjoint?
>>

62
TASK 4. Do what is indicated for each part. Write the complete syntax and what MATLAB will
return.
a. Compute the area of a parallelogram P with b. Determine if the following points are collinear
vertices at (-124), (3,1), (2,6), and (6,3), or not collinear. (-2, 5), (0, -1), (3, -9)
>> >>

c. Determine if the following points are coplanar


or not coplanar. (-4, 1, 0), (0,2,2), (4, 3, -1),
(0,0,1)
>>

TASK 5. By using Cramer's Rule, determine the solution to the following systems of linear
equations.

2𝑥1 + 4𝑥2 + 6𝑥3 = 2


{ 𝑥1 + 2𝑥3 = 0
2𝑥1 + 3𝑥2 − 𝑥3 = 5

63
Laboratory Activity 10
VECTOR SPACES, LINEAR COMBINATIONS AND SPANNING SETS

Objective
To understand the concept of vector spaces, linear combinations and spanning sets.

Intended Learning Outcomes (ILOs)


The students shall be able to:
1. Define a vector space and recognize some important vector spaces.
2. Show that a given set is not a vector space.
3. Determine whether a subset W of a vector space V is a subspace of V.
4. Determine subspaces of Rn,
5. Write a vector as linear combinations of other vectors.
Discussion
Let V be a set on which two operations (vector addition and scalar multiplication) are defined. If the
listed axioms are satisfied for every u, v, and w in V and every scalar c and d, then V is called a vector
space.
1. 𝑢 + 𝑣 is in V.
2. 𝑢 + 𝑣 = 𝑣 + 𝑢
3. 𝑢 + (𝑣 + 𝑤) = (𝑢 + 𝑣) + 𝑤
4. V has a zero vector 0 such that for every u in V, 𝑢 + 0 = 𝑢.
5. For every in V, there is a vector in V denoted by —u such that 𝑢 + (−𝑢) = 0
6. cu is in V.
7. 𝑐(𝑢 + 𝑣) = 𝑐𝑢 + 𝑐𝑣
8. (𝑐 + 𝑑)𝑢 = 𝑐𝑢 + 𝑑𝑢
9. 𝑐(𝑑𝑢) = (𝑐𝑑)𝑢
10. 1(𝑢) = 𝑢
A nonempty subset W of a vector space V is called a subspace of V when W is a vector space under the
operations of addition and scalar multiplication defined in V, The following closure conditions should
hold.
1. If u and v are in W, then u + v is in W.
2. If u is in W and c is any scalar, then cu is in W.

A vector v in a vector space V is called a linear combination of the vectors 𝑢1 , 𝑢2 , … , 𝑢𝑘 in V when v can
be written in the form 𝑣 = 𝑐1 𝑢1 + 𝑐2 𝑢2 + ⋯ 𝑐𝑘 𝑢𝑘 where 𝑐1 , 𝑐2 , … , 𝑐𝑘 are scalars.

Case 1: If the vectors in S are column matrices, then we construct a linear system whose coefficient
matrix A is 𝐴 = [𝑣1 𝑣2 … 𝑣𝑘 ] and whose right side is v. Let 𝑐 = [𝑐1 𝑐2 … 𝑐𝑘 ]𝑇 and b=v; then
transform the linear system Ac=b, using the rref command in MATLAB. If the system is shown to be
consistent, so that no rows of the form [0 0 … 0|𝑞], 𝑞 ≠ 0, occur, then the vector v can be written as a
linear combination of the vector S. In that case the solution of the linear system gives the values of the
coefficients.

Case 2. If the vectors in S are row matrices, then we construct the coefficient matrix
𝐴 = [𝑣1𝑇 𝑣2𝑇 … 𝑣𝑘𝑇 ] and set 𝑏 = 𝑉 𝑇 and then proceed with the method as described for Case 1.

64
Case 3. If the vector S are polynomials, then associate a column of coefficients with each
polynomial. Make sure any missing terms in the polynomial are associated with a zero coefficient. One
way to proceed is to use the coefficient of the next-higher-power term as the second entry, and so on. For
instance,
1 1 0
𝑡 2 + 2𝑡 + 1 → [2] , 𝑡 2 + 2 → [0] , 3𝑡 − 2 → [ 3 ]
1 2 −2
The problem is now solved using the procedure in Case 1.

Case 4. If the vectors in S are mxn matrices, then associate with each such matrix Aj a column vj
formed by stringing together its columns one after the other. In MATLAB this transformation is done by
using the reshape command. Then we proceed as in Case 1.

Let 𝑆 = {𝑣1 𝑣2 … 𝑣𝑘 } be a subset of a vectors space V. The set S is called a spanning set of V when
every vector in V can be written as a linear combination of vectors in S. In such cases it is said that S
spans V.
Resources
PC with MATLAB Software
Procedure
𝑎11 𝑎12 𝑎13
PART 1: Show that the set of all 2 x 3 matrices is a vector space. Note: 𝑉 = [𝑎 ].
21 𝑎22 𝑎23
Procedure:
1. Enter three 2 x 3 matrices and two scalars.
1 5 3 4 −6 −3 7 4 0
𝑢=[ ], 𝑣 = [ ], 𝑤 = [ ] , 𝑐 = 2, 𝑑 = 5.
0 −2 −1 1 5 0 9 6 −9

65
PART 2: Verify If the axioms for vector spaces hold true. Type the following commands in
MATLAB. Write on the space the output MATLAB returns for each command and then identify
the axiom that holds.

COMMANDS/OUTPUTS COMMANDS/OUTPUTS

>>𝑐 ∗ 𝑤 >>(𝑐 ∗ 𝑑) ∗ 𝑣
>> >>

Axiom:______________________________ >>(𝑐 ∗ 𝑑) ∗ 𝑣
>>𝑢 + 𝑣 >>
>> Axiom:_________________________
>>v+w _____
>> >>u + v
>>
Axiom:______________________________
>>(𝑢 + 𝑣) + 𝑤 Axiom:_________________________
_____
>>
>>(𝑐 + 𝑑) ∗ 𝑢
>>𝑢 + (𝑣 + 𝑤)
>>
>>
>>𝑐 ∗ 𝑢 + 𝑑 ∗ 𝑢
Axiom:______________________________
>>
>>𝑐 ∗ (𝑢 + 𝑣)
Axiom:_________________________
>> _____

Is the set of all 2 x 3 matrices a


>>𝑐 ∗ 𝑢 + 𝑐 ∗ 𝑣 vector space?

>> Why?
Axiom:______________________________
>>1*w
>>
Axiom:______________________________

66
PART 3: Let V be R3 and let W be the subset of v of vectors of the form [2 a b], where a and b are
any real numbers. Is W a subspace of V? Use the following MATLAB commands to help you
determine the answer. Write on the space on the right what MATLAB returns after typing the
commands.

COMMANDS OUTPUT

a1=fix(10*randn)

a2=fix(10*randn)

b1=fix(10*randn)

b2=fix(10*randn)

v=[2 a1 b1]

v+w

3*v
Is W a subspace of V? Why?
___________________________________________________________________________________
__________________________________________________________________________________.

PART 4: Use MATLAB to determine whether vector v is a linear combination of the members Of
set S and is v belongs to Span S.

2 1 1 1
a. If 𝑆 = {𝑣1 , 𝑣2 , 𝑣3 } , express 𝑣 = [1] as a linear combination of 𝑣1 = [2] , 𝑣2 = [0] , 𝑣3 = [1].
5 1 2 0

Enter the given vectors v, VI, v2, and v3 in MATLAB.

>>𝑣 = [2; 1; 5]; 𝑣1 = [1; 2; 1]; 𝑣2 = [1; 0; 2]; 𝑣3 = [1; 1; 0];

>>rref([𝑣1 𝑣2 𝑣3 𝑣])

67
Determine the rref of the augmented matrix

ans=

1 0 0 1
0 1 0 2
0 0 1 −1

The resulting rref should show that the linear system is consistent and that it has solutions
c1=1, c2=2 and c3=-1.
Therefore, the linear combination can be written as__________________________________________.
Now, since v can be written as linear combinations of vectors in S, then it can be said that v spans S.

6 −19
b. For 𝑆 = {𝐴, 𝐵} determined if 𝑀 = [ ] can be expressed as a linear combination of
10 7
2 −3 0 5
𝐴=[ ] 𝑎𝑛𝑑 𝐵 = [ ].
4 1 1 −2
Since here we have 2x2 matrices, we need to use the reshape command to make the matrices in column
vector form.
>>𝑀 = [6 − 19; 10 7]; >>Mr=reshape(M,4,1)
>>𝐴 = [2 − 3; 4 1]; Mr=
>>𝐵 = [0 5; 1 − 2]; 6
>>𝐴𝑟 = 𝑟𝑒𝑠ℎ𝑎𝑝𝑒(𝐴, 4,1) 10
𝐴𝑟 = -19
2 7
4 >>rref{[Ar Br Mr]}
-3 ans=
1
>>𝐵𝑟 = 𝑟𝑒𝑠ℎ𝑎𝑝𝑒(𝐵, 4,1) 1 0 3
𝐵𝑟 = 0 1 2
0
1 0 0 0
5 0 0 0
-2
___________________________________________________________________________________
___________________________________________________________________________________
Does M span S? Why?
___________________________________________________________________________________
___________________________________________________________________________________
___________________________________________________________________________________

68
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS:
TASK 1.

a. Let V be the set of all 2x2 matrices. Is V a vector space? Use the theorems on vector spaces to
verify. Write the syntax you used below.
>>

a. Let V be P2 and let W be the subset V of vectors of the form ax2 + bx+ 5 where a and b are
arbitrary real numbers. With each polynomial in W we associate a vector [a b 5 in R3. Construct
commands like those in ACTIVITY 2 to show that W is not a subspace of V.
>>

TASK 2.
Use MATLAB to determine whether vector v is a linear combination of the members of S.
1. 3.
𝑆 = {𝑣1 , 𝑣2 , 𝑣3 } 𝑆 = {𝐴1 , 𝐴2 , 𝐴3 }
= {[1 0 0 1], [0 1 1 0], [1 1 1 1]} 1 2 2 −1 −3 1
= {[ ],[ ],[ ]}
𝑣 = [0 1 1 1] 2 0 1 2 0 1
>> 𝑣 = 𝐼2
>>

69
2. 5.
𝑆 = {𝑣1 , 𝑣2 , 𝑣3 } 𝑆 = {𝑝1 (𝑡), 𝑝2 (𝑡), 𝑝3 (𝑡)}
1 2 −1 = {2𝑡 2 − 𝑡 + 1, 𝑡 2 − 2, 𝑡 − 1}
= {[ 2 ] , [−1] , [ 8 ]} 𝑣 = 𝑝(𝑡) = 4𝑡 2 + 𝑡 − 5
−1 0 −3
0 >>
𝑣=[ 5 ]
−2

4.
𝑆 = {𝑣1 , 𝑣2 , 𝑣3 }
1 0 2 2
2 1 1 1
= 1 , 2 , 0 , 1
0 1 0 1
{[ 1 ] [ 1 ] [  1 ] [ 1 ]}
0
1
𝑣= 1
2
[ 1 ]
>>

70
TASK 3. In each part, determine whether v belongs to span S, where
a) b)
𝑆 = {𝑣1 , 𝑣2 , 𝑣3 } 𝑆 = {𝑝1 (𝑡), 𝑝2 (𝑡), 𝑝3 (𝑡)}
= {[1 1 0 1], [1 − 1 0 1], [0 1 2 1]} = {𝑡 − 1, 𝑡 + 1, 𝑡 2 + 𝑡 + 1}
i. 𝑣 = [2 3 2 3] i. 𝑝(𝑡) = 𝑡 2 + 2𝑡 + 4

>> >>

ii. 𝑣 = [2 − 3 − 2 3] ii. 𝑝(𝑡) = 2𝑡 2 + 𝑡 − 2

>> >>

iii. 𝑣 = [0 1 2 3] iii. 𝑝(𝑡) = −2𝑡 2 + 1

>> >>

71
Laboratory Activity 11
LINEAR INDEPENDENCE,BASIS AND DIMENSIONS
Objective
To understand the concepts of linear independence, dependence, basis and dimensions of spaces.
Intended Learning Outcomes (ILOs)
The students shall' be able to:
1. Determine whether a set of vectors in a vector space V is linearly independent.
2. Recognize bases in the vector spaces Rn, Pn, and Mm, n.
3. Find the dimension of a vector space.
Discussion

A set of vectors 𝑆 = {𝑣1 , 𝑣2 , 𝑣3 , … , 𝑣𝑘 } in a vector space V is called linearly independent when the
vector equation 𝑐1 𝑣1 + 𝑐2 𝑣2 + ⋯ 𝑐𝑘 𝑣𝑘 has only the trivial solution 𝑐1 = 0, 𝑐2 = 0, … , 𝑐𝑘 = 0. If there
are also nontrivial solutions, then S is called linearly dependent.
Testing for Linear Dependence and Linear Independence
Let 𝑆 = {𝑣1 , 𝑣2 , 𝑣3 , … , 𝑣𝑘 } be a set of vectors in a vector space V. To determine whether S is linearly
dependent or linearly independent, use the following steps.
1. From the vector equation 𝑐1 𝑣1 + 𝑐2 𝑣2 + ⋯ 𝑐𝑘 𝑣𝑘 = 0, write a system of linear equations in the
variables 𝑐1 , 𝑐2 , … , 𝑐𝑘 .
2. Use Gaussian elimination to determine whether the system has a unique solution.
3. If the system has only the trivial solution 𝑐1 = 0, 𝑐2 = 0, … , 𝑐𝑘 = 0, then the set S is linearly
independent. If the system also has nontrivial solutions, then S is linearly dependent.
Two vectors u and v and in a vector space V are linearly dependent if and only if one is a scalar
multiple of the other.

A set of vectors 𝑆 = {𝑣1 , 𝑣2 , 𝑣3 , … , 𝑣𝑘 } in a vector space V is called a basis for V when the following
conditions are true.
1. S spans V
2. S is linearly independent

If 𝑆 = {𝑣1 , 𝑣2 , 𝑣3 , … , 𝑣𝑘 } is a basis for a vector space V, then every vector V can be written in one
and only one way as a linear combination of vectors in S.

If a vector space V has one basis with n vectors, then every basis for V has n vectors.

If a vector space V has a basis containing n vectors, then the number n is called the dimension of
V, denoted by dim(V) = n, When V consists of the zero vector alone, the dimension of V is defined as
zero.

Resources
PC with MATLAB Software

72
Procedure
PART 1. Do as indicated.
b. Determine whether the set of vectors in
P2 is linearly independent or dependent.
{𝑣 }
𝑆 = 1 , 𝑣2 , 𝑣3 = {(1,2,3), (0,1,2), (−2,0,1)} 𝑆 = {1 + 𝑥 − 2𝑥 2 , 2 + 5𝑥 − 𝑥 2 , 𝑥 + 𝑥 2 }
Since the given set of vectors are in
polynomial form, we associate each
a. Determine whether the set of vectors in R3 is linearly polynomial to a column vector
independent or dependent.
1
1 + 𝑥 − 2𝑥 2 → [ 1 ] ; 2 + 5𝑥 − 𝑥 2
−2
3 0
This is the same as the procedure in determining linear → [ 5 ] ; 𝑥 + 𝑥 2 → [1 ]
−1 1
combinations. Construct that augmented matrix but this >>𝐴 = [1 1 − 2; 2 5 − 1; 0 1 1]′
time b is a zero vector. A=
1 2 0
>>𝐴 = [1 2 3; 0 1 2; −2 0 1]′ 1 5 1
−2 −1 1
A=
>>𝑏 = 𝑧𝑒𝑟𝑜𝑠(3,1);
1 0 −2 >>𝑟𝑟𝑒𝑓([𝐴 𝑏])
2 1 0 ans=
3 2 1
1.0000 0  0.6667 0
>>𝑏 = 𝑧𝑒𝑟𝑜𝑠(3,1) 0 1.0000 0.3333 0
0 0 0 0
b=
0
0 >>format rat
0 >>ans
ans=
>>𝑟𝑟𝑒𝑓([𝐴 𝑏]) 1 0  2/3 0
0 1 1/ 3 0
ans=
0 0 0 0
1 0 0 0
0 1 0 0
0 0 1 0 Conclusion:
__________________________________
__________________________________
__________________________________
____________.

Conclusion:
______________________________________________
______________________________________________
_________________________________.

c. Determine whether the set of vectors in M2,2 is linearly PART 2


independent or dependent.

73
a. Show that the set 𝑆 = {(1,1), (1, −1)} is
2 1 3 0 1 0 a basis for R2.
𝑆 = {[ ],[ ],[ ]}
0 1 2 1 2 0 According to the definition of a basis for a
vector space, you must show that S spans
We have to reshape the given vectors in S into a column R2 and is linearly independent. To
matrix. determine if S spans R2, consider a vector
in R2 of the form 𝑣 = (𝑥1, 𝑥2) .Writing v
>>𝑣1 = [2 1; 0 1]; 𝑣2 = [3 2; 2 1]; 𝑣3 = [1 0; 2 0]; as a linear combination or vectors in S, we
have
>>𝐴 = [𝑟𝑒𝑠ℎ𝑎𝑝𝑒(𝑣1,4,1)𝑟𝑒𝑠ℎ𝑎𝑝𝑒(𝑣2,4,1)𝑟𝑒𝑠ℎ𝑎𝑝𝑒(𝑣3,4,1)]
𝑐1 (1,1) + 𝑐2 (1, −1) = (𝑥1 , 𝑥2 )
A= 𝑐1 + 𝑐1 = 𝑥1
2 3 1 𝑐1 − 𝑐2 = 𝑥2
0 2 2 Let us get the determinant of the coefficient
1 2 0 matrix of the system
1 1 0
>>𝐴 = [1 1; 1 − 1]
>>𝑏 = 𝑧𝑒𝑟𝑜𝑠(4,1); >>det(𝐴)

>>𝑟𝑟𝑒𝑓([𝐴 𝑏]) ans=

ans= -2

1 0 0 0 The determinant is non-zero which means


that the system will have a unique solution
0 1 0 0
and that any vector in R2 can be expressed
0 0 1 0 as a linear combination of vectors in S
0 0 0 0 therefore S spans R2.

To determine if S is linearly independent


Conclusion: >>A=[1 1; 1-1]';
______________________________________________ >>b=zeros(2,1);
______________________________________________ >>rref([A b])
_________________________________. ans=
1 0 0
0 1 0

The system has only one trivial solution and


so S is linearly independent. Therefore S is
a basis for R2.

b. Show that the set of vectors is a basis for 𝑀5,1

74
1 0 0 0 0 c. Let V=R3 and S={vI, v2, v3, v4, v5},
where
2 1 0 0 0 𝑣1 = [1 0 1]. 𝑣2 = [0 1 1], 𝑣3 =
𝑆= 1 , 3 , 2 , 0 , 0 [1 1 2]
3 2 1 2 0 𝑣4 = [1 2 1], 𝑎𝑛𝑑 𝑣5 = [−1 1 −
2]
{[ 4 ] [ 3 ] [ 5 ] [  3 ] [  2 ]}

>>A = [1 2 − 1 3 4; 0 1 3 − 2 3; 0 0 2 − 1 5; 0 0 0 02]′ ; Find a subset of S that is a basis of R3.

≫= 𝑏 = 𝑧𝑒𝑟𝑜𝑠(5,1); Form the augmented matrix of S and


determine its rref:
>>𝑟𝑟𝑒𝑓([𝐴 𝑏])
>>𝐴 =
ans= [1 0 1; 0 1 1; 1 1 2; 1 2 1; −1 1 − 2]′;

1 0 0 0 0 >>𝑏 = 𝑧𝑒𝑟𝑜𝑠(3,1);

0 1 0 0 0 >> 𝑟𝑟𝑒𝑓([𝐴 𝑏])


0 0 1 0 0
ans=
0 0 0 1 0
1 0 1 0 2 0
0 0 0 0 0
0 1 1 0 1 0
Since the given 'is an n-dimensional vector, we only need
to check for one condition (either S spans V or S is linearly 0 0 0 1 1 0
independent). Since the leading I's appear on the column
1, column 2 and column 4 then {VI, v2, v4}
Based on the rref of S, it can be seen that there is only is a basis for R3.
one trivial solution. Therefore S is linearly independent
and S is a basis for 𝑀5,1 . The dimension of S is 3.

75
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS:

TASK 1.
a) Determine whether S is linearly 1 0 2 2
independent or linearly
dependent. 2 1 1 1
i. 𝑆 = {[1 0 0 1], [0 1 1 0], [1 1 1 1]} iii. 𝑆 = 1 , 2 , 0 , 1
0 1 0 1
>>
{[ 1 ] [ 1 ] [  1 ] [ 1 ]}
>>

iv. 𝑆 = {2𝑡 2 − 𝑡 + 3, 𝑡 2 + 2𝑡 − 1,4𝑡 2 − 7𝑡 + 11}

1 2 2 −1 −3 1
ii. 𝑆 = {[ ],[ ],[ ]}
1 0 1 2 0 1 >>
>>

76
TASK 2: Determine whether S is a basis for V.
2 1
b.) Let 𝑣1 = [−1] , 𝑣2 = [ 2 ] , 𝑣3 = a.) 𝑆 = {[1 2 1], [2 1 1], [2 2 1]} in 𝑉 = 𝑅 3
3 −1
4 >>
[−7]
1

Determine whether v is in span


{𝑣1 , 𝑣2 , 𝑣3 } for each of the following, and
if it is, find the coefficients that express v
as a linear combination of 𝑣1 , 𝑣2 , 𝑎𝑛𝑑 𝑣3 .

1
i. 𝑣 = [1]
1

>>

b.) 𝑆 = {2𝑡 − 2, 𝑡 2 − 3𝑡 + 1,2𝑡 2 − 8𝑡 + 4} in


𝑉 = 𝑃2 .
>>

3
ii. 𝑣 = [1]
2

>>

77
1 2 1 0 0 2 2 4 1 0
b.) 𝑆 = {[ ],[ ],[ ],[ ],[ ]}
1 2 1 1 0 1 2 4 0 1
c.) 𝑆 = {[1 1 0 0], [2 1 1 −
1], [0 0 1 1], [1 2 1 2]} in 𝑉 = 𝑅4 What is dim span 5? Does span 𝑆 = 𝑀2,2 ?

>> >>

TASK 4. Determine a subset of S that


is a basis for span S. c.) 𝑆 = {𝑡 − 2,2𝑡 − 1,4𝑡 − 2, 𝑡 2 − 𝑡 + 1, 𝑡 2 + 2𝑡 + 1}

What is dim span S? Does span 𝑆 = 𝑃2 ?


a.) 𝑆 = {[1 1 0 0], [−2 − 2 0 0],
[1 0 2 1], [2 1 2 1], [0 1 1 1]} >>

What is the dimension of Span S? Does


span 𝑆 = 𝑅 4?

>>

78
Laboratory Activity 12
RANK OF A MATRIX
Objective
To understand the rank of a matrix, row spaces, column spaces and null spaces.
Intended Learning Outcomes (ILOs)
The students shall be able to:
1. Find a basis for the row space, a basis for the column space, and the rank of a matrix.
2. Find the nullspace of a matrix.

Discussion
Let A be an mxn matrix.
1. The row space of A is the subspace of Rn spanned by the row vectors of A.
2. The column space of A is the subspace of Rm spanned by the column vectors of A.

RowVectorsofA
a a  a
11 12

1n
a , a ,  , a1n 
a a a a , a ,, a2 n 
11 12
21 22 2n
𝐴=
   21 22

[ a m1 a m2
 a mn ] a , a
m1 m2
,  , a mn

ColumnVectorsofA
a a  a
11 12 1n  a11   a12   a1n 
a a  a     
 a21  a22    a2 n 
21 22 2n
𝐴=
          
a a  a     
[ m1 m2 mn ]
am1 am 2  amn

If an mxn matrix A is row-equivalent to an mxn matrix B, then the row space of A is equal to the row
space of B.

If a matrix A is row-equivalent to a matrix B in row-echelon form, then the nonzero row vectors B form
a basis for the row space of A.

If A is an mxn matrix, then the row space and column space of A have the same dimension.

The dimension of the row(or column) space of a matrix A is called the rank of A and is denoted by
rank(A).

If A is an mxn matrix, then the set of all solutions of the homogenous system of linear equations Ax=0
is a subspace of Rn called the nullspace of A and is denoted by N(A). So,
𝑁(𝐴) = {𝑥 ∈ 𝑅 𝑛 : 𝐴𝑥 = 0}
The dimension of the nullspace of A is called the nullity of A.

If A is an mxn matrix of rank r, then the dimension of the solution space of AFO is n-r. That is,
𝑛 = 𝑟𝑎𝑛𝑘(𝐴) + 𝑛𝑢𝑙𝑙𝑖𝑡𝑦(𝐴)

79
Resources
PC with MATLAB Software
Procedure
PART 1: The rank of a matrix A can be obtained in MATLAB by
a. Enter the following commands in using the syntax rank(A).
MATLAB What Is rank(A)? What is rank(B)?

>>𝐴 = [1 2 3; 4 0 1]; What conjecture can you make regarding the number of
row spaces and the rank of a given vector?
>>𝑟𝑟𝑒𝑓(𝐴) _____________________________________________
_____________________________________________
ans= ______________________________
1 0 1/4
0 1 11/8 PART 2:
a. Enter the following matrix A in MATLAB
We have two non-zero rows in rref(A) which 3 9  7  2 6  3  1
means that the row space of A is a 2- 2 6 0 8 4 12 4 
dimensional subspace of R3. A basis for this 𝐴= 
rowspace is formed by the vectors (1,0,1/4) 2 6 5 18 4 33 11 
and (0,1,11/8)  
3 9  2 8 6 18 6 
b. Enter the following commands in
MATLAB Verify in MATLAB that rref(A) is
>>𝐵 = 𝐴′ ;
rref(A)
>>rref(B) ans =

ans= 1 3 0 4 2 0 0
1 0 0 0 1 2 0 0 0
0 1
0 0 0 0 0 0 0 1 1/ 3
0 0 0 0 0 0 0
Following that in (a), what are the row spaces
of B and what is the basis for B?
Leading ones in the column 1, 4 and 6. The
corresponding column of the original matrix A form a
basis for column space of A. These are

 3   2  3
 2 8   12 
   
v1  2, v2   18 , v3   33 
     
 3 8   18 

80
Solve the leading variables:

𝑥1 = −3𝑥2 −2𝑥5
𝑥4 = −2𝑥5
b. What is the rank of A? 1
𝑥5 = 𝑥7
3
N=rank(A)+nullity(A)

Nullity(A)=N-rank(A) Set 𝑥2 = 𝑟, 𝑥3 = 𝑠, 𝑥5 = 𝑡, 𝑥7 = 𝑤 and so

What is the nullity of A?  x1   3r  2t   3 0  2 0


   
r   1  0   0  0
c. To show that a vector b is a column  x2          
space of matrix A you need to show  x   s   0  1  0  0
that the linear system Ax=b is  3          
consistent. That is you need to show x4    2t   r  0   50  t  2  w 0 
   t   0  0   1  0
 x5   1
that rank(A) = rank ([Ab]). That
means you are checking to see if b is        1 
 x6   w   0  0   0   
the vector space spanned by the    3   0  0   0  3
column vectors or A or not. x
 7  w        1 
Using the same matrix A in a, which
of the following are in the 'column Therefore,
space of A?
i. (6, 4, 4, 6)
 3 0    2 0 
ii. (6, 16, 4, 0) 1 0  0 0 
iii. (-4, 16, 40, 20)        
 0  1 0 0 
PART 3:        
Enter the following matrix in MATLAB v1   0 , v2  0, v3   2 , v4  0
 0  0  1  0 
1 3 0 2 3 1
6        
 2  6  0  0  0 1 
0  2  8 3 1   0  0  2
A  0       
3 9 0 0 6 6 2
 
 1  3 0 1 0 9 3 form a basis for the solution of the solution
space Ax-O. This is called the null space of A.
Verify that the rref of a is

1 3 0 0 2 0 0
0 0 0 1 2 0 0 
 1
0 0 0 0 0 1 
 3
0 0 0 0 0 0 0 

81
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS
TASK 1: Determine two bases for each row Determine two bases for each column space of
space of A that have no vectors in common. A that have no vectors in common.

1 3 1  1 3 1 
2 5 0 2 5 0
a. 𝐀 =   a. 𝐴 =  
4 11 2 4 11 2
   
6 9 1  6 9 1 
>>rref(A) >> rref(A)
ans= ans=
1 0 0 1 0 0
0 1 0 0 1 0
0 0 1 0 0 1
0 0 0 0 0 0

2 1 2 0
0 0 0 0

b. 𝐴 = 1 2 2 1
2 1 2 0  
0 4 5 6 2
 0 0 0 3 3 4 1
b. 𝑨 = 1 2 2 1 >>
 
4 5 6 2
3 3 4 1
>>

82
TASK 2: Compute the rank and nullity of each
of the following matrices: 1 2 1 𝑥1 3
b. [1 1 0 ] [𝑥2 ] = [3]
3 2 1 2 1 −1 𝑥3 3
a. 𝐴 = [1 2 −1] >>
2 1 3
>>

1 2 1 2 1
2 1 0 0 2
b. 𝑨 = 
1  1  1  2 1
 
3 0  1  2 3
1 2  3
>> 2 
0  x1  2
c.   
2 1   x 2   3
   
 1 2  2
>>

Determine which of the following linear


systems is consistent:

1 2 4  1  x1  21
0 1 2 0      8 
a.
   x2   
3 1 1  2  x3 16 
>>

83
Laboratory Activity 13
STANDARD INNER PRODUCTS
Objective
The students should be able to understand the concepts of vector inner products.
Intended Learning Outcomes (ILOs)
The students shall be able to:
1. Find the length of a vector and find a unit vector.
2. Find the distance between two vectors.
3. Find a dot product and the angle between two vectors and determine orthogonality.
4. Find the cross product of two vectors in R3 and some applications.
Discussion
1. The length, or norm, of a vector 𝑣 = (𝑣1 , 𝑣2 , … , 𝑣𝑛 )
2. This shows that the length of a vector is always positive. The norm of a vector is zero if and
only if we are dealing with a zero vector.
3. Let v be a vector in Rn and let c be a scalar. Then ||cv||=|c|||v||.
𝑣
4. If v is a nonzero vector in Rn, then the vector 𝑢 = has length 1 and has the same direction
||𝑣||
as v. The vector u is called the unit vector in the direction of v.
5. The distance between two vectors u and v in Rn is 𝑑(𝑢, 𝑣) = ||𝑢 − 𝑣||.
6. The dot product of 𝑢 = (𝑢1 , 𝑢2 , … , 𝑢𝑛 ) and 𝑣 = (𝑣1 , 𝑣2 , … , 𝑣𝑛 ) is the quantity
𝑢 ∗ 𝑣 = 𝑢1 𝑣1 + 𝑢2 𝑣2 + ⋯ + 𝑢𝑛 𝑣𝑛
7. Properties of the dot product
If u,v and w are vectors in Rn and c is a scalar, then the following properties are true.
a.) 𝑢 ∗ 𝑣 = 𝑣 ∗ 𝑢
b.) 𝑢 ∗ (𝑣 + 𝑤) = 𝑢 ∗ 𝑣 + 𝑢 ∗ 𝑤
c.) 𝑐(𝑢 ∗ 𝑣) = (𝑐𝑢) ∗ 𝑣 = 𝑢 ∗ (𝑐𝑣)
2
d.) 𝑣 ∗ 𝑣 = ||𝑣||
e.) 𝑣 ∗ 𝑣 ≥ 0, 𝑎𝑛𝑑 𝑣 ∗ 𝑣 = 0 𝑖𝑓 𝑣 = 0
𝑣
8. The angle 𝜃 between two nonzero vectors in Rn is given by 𝑐𝑜𝑠𝜃 = 𝑢 ∗ ,0 ≤ 𝜃 ≤ 𝜋
||𝑢||||𝑣||
9. Two vectors u and v in Rn are orthogonal when 𝑢 ∗ 𝑣 = 0
10. Let 𝑢 = 𝑢1 𝑖 + 𝑢2 𝑗 + 𝑢3 𝑘 and 𝑣 = 𝑣1 𝑖 + 𝑣2 𝑗 + 𝑣3 𝑘 be vectors in R3.The cross product of u
and v is the vector 𝑢 ∗ 𝑣 = (𝑢2 𝑣3 − 𝑢3 𝑣2 )𝑖 − (𝑢1 𝑣3 − 𝑢3 𝑣1 )𝑗 + (𝑢1 𝑣2 − 𝑢2 𝑣1 )𝑘.
11. Algebraic Properties of the Cross Product
If u, v, and w are vectors in R3 and c is a scalar, then the following properties are true.

a.) 𝑢 ∗ 𝑥 = −(𝑣 ∗ 𝑢)
b.) 𝑢 ∗ (𝑢 + 𝑤) = (𝑢 ∗ 𝑣) + (𝑢 ∗ 𝑤)
c.) 𝑐(𝑢 ∗ 𝑣) = 𝑐𝑢 ∗ 𝑣 = 𝑢 ∗ 𝑐𝑣
d.) 𝑢 ∗ 0 = 0 ∗ 𝑢 = 0
e.) 𝑢 ∗ 𝑢 = 0
f.) 𝑢 ∗ (𝑣 ∗ 𝑤) = (𝑢 ∗ 𝑣) ∗ 𝑤
12. Geometric Properties of the cross product
If u and v are nonzero vectors in R3, then the following properties are true.
a.) 𝑢 ∗ 𝑥 is orthogonal to both u and v.
b.) The angle 𝜃 between u and v is given by ||𝑢 ∗ 𝑣|| = ||𝑢||||𝑣||𝑠𝑖𝑛𝜃.
c.) U and v are parallel if 𝑢 ∗ 𝑣 = 0.
d.) The parallelogram having u and v as adjacent sides has an area ||𝑢 ∗ 𝑣||

84
Resources
PC with MATLAB Software
Procedure
1. To find the length of 𝑣 = (0, −2, 1, 4, −2) in 2. To find the unit vector in the direction of
R5 using MATLAB, 𝑉 = (3, −1, 2 ) and verify that this
>>𝑣 = [0 − 2 1 4 − 2]; vector has a length 1.

>>𝑛𝑜𝑟𝑚(𝑣) >>𝑢 = [3 − 1 2];

ans= >>𝑢𝑛𝑖𝑡 = (𝑙/𝑛𝑜𝑟𝑚(𝑢)) ∗ 𝑢


5 unit=
809 929 929
In R3, what is the length of −
1009 347 1738
2 2 3
𝑣 = ( 17 , − 17 , 17) ?
√ √ √ >>norm(unit)
>> ans =
1

3. The distance between u = (0,2,2) and 5. Finding the angle 𝜃 between


v = (2,0,1) is computed as 𝜋 𝜋 3𝜋 3𝜋
>>u = [0 2 2]; 𝑢 = (cos , 𝑠𝑖𝑛 ) , 𝑣 = (𝑐𝑜𝑠 , 𝑠𝑖𝑛 )
6 6 4 4
involves the following MATLAB syntax
>>v = [2 0 1]; >> u = [cos(pi/6) sin(pi/6)];

>> distance = norm(u ∗ v) >> v = [cos(3 ∗ pi/4) sin(3 ∗ pi/4)l;

distance= >> costheta = (dot(u, v))/(norm(u) ∗


norm(v))
3
costheta =

What is the distance between u=(3, -1, 0, -3) and -675/2608


v=(4, 0, 1, 2)?
>> theta = acos(costheta)
>>
theta=

2485/1356

Compute the dot product of u=(1, 2, 0, -3) and >> theta = theta ∗ (180/pi)
v=(3, -2, 4, 2) as
>>u=[1 2 0 -3]; theta=
105
>>v=[3 -2 4 2];

>>dot(u,v)

ans=
-7

85
Let 𝑢 = (2, −2), 𝑣 = (5, 8) and 𝑤 = (−4, 3). What is the function of acos(costheta)?
Find each quantity. _______________________________________
_______________________________________
a. 𝑢∗𝑣
b. (𝑢 ∗ 𝑣)𝑤
c. 𝑢 ∗ (2𝑣)
2 What is the use of (180/pi)?
d. ||𝑤||
_______________________________________
e. 𝑢 ∗ (𝑣 − 2𝑤)
_______________________________________

6. Let u=I-2j+k and v=2i+j-2k.


Are the vectors orthogonal? Why?
Find each of the following:
_______________________________________
a. 𝑢𝑥𝑣
_______________________________________
b. 𝑣𝑥𝑢
c. 𝑣𝑥𝑣

>> u = [1 − 2 1];
7. Find a unit vector orthogonal to both
u=I-4j+k and v=2i+3j
>> v = [2 1 − 2];
>> u = [1 − 41];
>> v = [2 3 0];
>> a = cross(u, v) >>unit = cross(u, v)/(norm(u) ∗ norm(v))
unit=
a= -1020/5201 239/1828
919/1278
3 4 5 Check using the dot product if they are
orthogonal
>> b = cross(v, u) >>dot(unit, u)
b= ans =
0
-3 -4 -5
>>dot(unit, v)
>> c = cross(v, v) ans=
-1/18014398509481984
0 0 0 >>format short
Is cross product commutative?
>> dot(unit, v)
_______________________________________
ans =
-5.5511e-17
Why is it that the cross product of two equal
8. Find the area of the parallelogram that
vectors is a zero vector?
has u=3i+4j+k and v=-2j+6k as adjacent
_______________________________________
sides.
>> u = [−3 4 1];
>> v = [0 − 2 6];
>> Area = norm(cross(u, v))
Area =

86
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS
1. Compute for the dot products of the 2. Determine the length of each of the following
following pairs of vectors: vectors:
a. v=[1 4 -1], w=[7 2 0]

>> 1 
0 0 
2 4  
a.) 𝑢 = [ 2 ] ; b.) 𝑣 =  ; c.) 𝑤 = 1 
1 4 −1   3  
 1 2   0 
0 3
b. 𝑣 =   ,w   
0 3 >>
   
6  1
>>

3. Determine the distance between each of the


following pairs of vectors.
c. Let 𝑎 = [3 − 2 1]. Find a value of k so 2 2
that the dot product of a with a. 𝑢 = [0] , 𝑣 = [−1]
𝑏 = [𝑘 1 4] is zero. Verify your results
3 1
in MATLAB.
>>

b. 𝑢 = [1 0 4 3]; 𝑣 = [−1 1 2 2]
>>

87
c. Determine the lengths of the sides of the
triangle ABC, which has vertices in R3; given by 5. Determine a unit vector in the direction of vectors
A(1, 3, −2), B(4, −1, 0), C(1, 1, 2). u, v and w in PROBLEM 2. Verify that what you
obtained are indeed unit vectors.
>>
>>

4. Find the angle between the given pairs of


vectors. Express angles in degree measurement.

a. u = [3 2 4 0], v = [0 2 − 1 0]

>>

6. Determine the cross product of the following:

a. 𝑢 = 𝑖 − 2𝑗 + 3𝑘; 𝑣 = 𝑖 + 3𝑗 + 𝑘

>>

b. 𝑢 = [1 0 0 2]; 𝑣 = [0 3 − 4 0]

>>

b. 𝑢[1 0 3], 𝑣 = [1 − 1 2]

>>

88
7. Find the volume of the parallelepiped with vertex at the origin and edges
𝑢 = [3 − 2 1]; 𝑣 = [1 2 3]; 𝑤 = [2 − 1 2].

>>

1 3 1
8. Find a unit vector that is both orthogonal to u = −3i + 2j − 5k; and v = 2 i − 4 j + 10 k. Verify your
answer using the dot product.

>>

89
Laboratory Activity 14
EIGENVALUES, EIGENVECTORS AND DIAGONALIZATION
Objective
Explore MATLAB's built-in eigenvalue solver to obtain eigenvalues, set-up eigenvectors and
determine if a matrix is diagonalizable.
Intended Learning Outcomes (ILOs)
The students should be able to:
1. Obtain the eigenvalues of an nxn matrix by using a built-in MATLAB command.
2. Use MATLAB to determine the eigenvectors of a given square matrix.
3. Determine whether a given matrix is diagonalizable or not.

Discussion
Let A be an nxn matrix, v an nx1 vector and 𝜆 a scalar. We call v an eigenvector of matrix A with
eigenvalue 𝜆 if 𝑣 ≠ 0 and 𝜆𝑣 = 𝜆𝑣.

We can rewrite the above equation as (A − λI) • v = 0. Since v ≠ 0, this has a solution only if (A − λI)
is singular. Hence we could define an eigenvalue alternatively the number 𝜆 that when subtracted from
each diagonal entry of the n x n matrix A, transforms A into a singular matrix. Thus we can determine
the eigenvalues of A by solving det(A − 𝜆I) = 0. This equation will produce the so called characteristic
polynomial. The eigenvectors are obtained from the previous definition.

Remarks:
- The diagonal entries of a diagonal matrix A are eigenvalues of A (also for upper and lower
triangular matrices),
- A square matrix A is singular if and only if zero is an eigenvalue of A.
- The trace of an n x n matrix A equals the sum of its eigenvalues.
- The determinant of an n x n matrix A equals the product of its eigenvalues.
- For an n x n matrix A the characteristic equation is an nth order polynomial in A. Its solution
may be n distinct values or may contain repeated roots (or it may contain zeros as well).
Moreover there is no guarantee that the eigenvalues are real, they may be complex as well.
Resources
PC with MATLAB Software
Procedure
1. The MATLAB command poly(A) produces the coefficients of the characteristic polynomial of the
square matrix A, beginning with the highest degree term.
Given the matrix A=, we find the characteristic polynomial Of this matrix.

Input and verify the following in MATLAB:

>>A=[2 1 3; 3 7 1; 6 9 0];

>>poly(A)

>>ans=

1 -9 -16 57

This corresponds to a characteristic polynomial of 𝜆3 − 9𝜆2 − 16𝜆 + 57 = 0.

90
2. If we set then the command root(p calculates the roots of the characteristic polynomial of the matrix
A. We use this sequence of commands on the previous matrix.

Input and verify in MATLAB:

>>p=poly(A)

p=

1 -9 -16

>>roots(p)

ans =

2798/279
-1958/663
1097/570
2798 1958 1097
Hence the eigenvalues of A are 𝜆1 = 279
, 𝜆2 =− 663
, 𝜆3 = 570

3. The MATLAB command produces a diagonal matrix D containing the eigenvalues of A on the
diagonal, and a matrix V whose columns are the corresponding eigenvectors. Let us use this command
on our given matrix A.

Input and verify in MATLAB:


>>[V, D] = eig(A)
V=
−517/147 −873/1043 −901/1708
−233/398 335/638 314/4245
−857\1194 −892/5793 793/937

D=
2798/279 0 0
0 1097/570 0
0 0 −1958/663

−517/1491 −873/1043
Thus, the eigenvectors of A are 𝑉1 = [ −233/398 ] , 𝑉2 = [ 335/638 ]
−875/1194 −892/57923

−901/1708
𝑉3 = [ 314/4245 ]
793/937

−1 1
4. Let 𝐴 = | |. We can use MATLAB to diagonalize A as follows. First compute the eigenvalues
2 4
and eigenvectors of A using the command [P, D] = eig(A). The diagonal matrix D contains the
eigenvalues of A, and the corresponding igenvectors from the column of P.
Verify that P digonalizes A by showing that 𝑃 −1 𝐴𝑃 = 𝐷.

91
Input and verify in MATLAB:

>>𝐴 = [−11; 2 4];

>>[𝑃, 𝐷] = 𝑒𝑖𝑔(𝐴)

P=

−522/557 −1044/5705
157/450 −1863/1895

D=

−505/368 0
0 1609/368

>>>>𝑖𝑛𝑣(𝑃) ∗ 𝐴 ∗ 𝑃

ans=

−505/368 0
0 1609/368

Since 𝑃−1 𝐴𝑃 = 𝐷, then P can be said to diagonalize A,

92
NAME:
SCORE:

SECTION: ACTIVITY NO.:

INSTRUCTOR: DATE PERFORMANCE/SUBMITTED

ASSESSMENT TASKS:

Perform what is indicated for each task. Write all the important syntaxes and write all outputs in
RATIONAL FORMAT.
Task 1
Set-up the correct characteristic polynomial of
the following matrices.

2 3
(a) 𝐴 = [ ]
1 4 1 2 3 4
>>
5 6 7 8
(c) 𝐴 =  
 9 10 11 12 
 
13 14 15 16 

>>

Characteristic polynomial:
_______________________________________

1 2 −2
(b) 𝐴 = [−2 5 −2]
−6 6 −3

>>

Characteristic polynomial:
Characteristic polynomial: _______________________________________

93
TASK 2 TASK 3
Find the eigenvalues of the following matrices: Obtain the eigenvalue and eigenvectors of the
following matrices:
−2 3
(a) 𝐴 = [ ]
1 −4 2 3
(a) 𝐴 = [ ]
1 4
>>
>>

Eigenvalues: Eigenvalues:
_______________________________________ _______________________________________
Eigenvectors:
1 2 −2 _______________________________________
(b) 𝐴 = [−2 5 −2] 1 2 −2
−6 6 −3 (b) 𝐴 = [−2 5 −2]
−6 6 −3
>>
>>

Eigenvalues: Eigenvalues:
_______________________________________ _______________________________________
Eigenvectors:
1 2 3 4 _______________________________________
5 6 7 8 
(c) 𝐴 =  1 2 3 4
 9 11 10 12  5 6 7 8
  (c) 𝐴 =  
13 14 15 16   9 10 11 12 
 
>> 13 14 15 16 

>>

Eigenvalues:
_______________________________________
Eigenvalues Eigenvectors:
_______________________________________ _______________________________________

94
TASK 4 TASK 5
Let Use MATLAB to determine if the given matrix
2 2 −3 is diagonalizable or not.
𝐴=[ 2 1 −6]
−1 −2 0 4 −5
Use MATLAB to find the eigenvalues and (a) 𝐴 = [ ]
2 3
corresponding eigenvectors of
>>
A

>>

Conclusion:
Eigenvalues: _______________________________________
_______________________________________
Eigenvectors: 2 2 −3
_______________________________________ (b) 𝐴 = [ 2 1 −6]
−1 −2 0
AT
>>
>>

Eigenvalues:
_______________________________________
Eigenvectors:
_______________________________________
Conclusion:
A-1 _______________________________________

>>

Eigenvalues:
_______________________________________
Eigenvectors:
_______________________________________

What do you observe?


_______________________________________
_______________________________________
_______________________________________
_______________________________________

95
96

You might also like