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

Numerical Methods for

Engineers
EE0903301
Lecture 10: Matrix Algebra Overview
Dr. Yanal Faouri
Linear Systems

• It is the case of determining the values x1, x2, . . . , xn that simultaneously satisfy a set of equations:

• Where the a’s are constant coefficients, the b’s are constants, the x’s are unknowns, and n is the
number of equations. All other algebraic equations are nonlinear.
Matrix Algebra Overview: Matrix Notation

• A matrix consists of a rectangular array of elements represented by a single symbol.


• A square matrices occur when m = n, where the diagonal consisting of the elements a11, a22, … ann is termed the
principal or main diagonal of the matrix.

Row Vector
Size = 1 x n

Column Vector
Size m x 1

Matrix, size = m x n
Matrix Algebra Overview: Matrix Notation

• There are a number of special forms of square matrices that are important and should be noted:
• A symmetric matrix is one where the rows equal the columns—that is, aij = aji for all i’s and j’s.

• A diagonal matrix is a square matrix where all elements off the main diagonal are equal to zero.
• An identity matrix is a diagonal matrix where all elements on the main diagonal are equal to 1.
• An upper triangular matrix is one where all the elements below the main diagonal are zero.
• A lower triangular matrix is one where all elements above the main diagonal are zero.
• A banded matrix has all elements equal to zero, with the exception of a band centered
on the main diagonal:
• The banded matrix shown has a bandwidth of 3 and is given a special name: the tridiagonal
matrix.
Matrix Algebra Overview: Matrix Operating Rules

• Two m by n matrices are equal if, and only if, every element in the first is equal to every element in the second,
that is, [A] = [B] if aij = bij for all i and j.
• Addition ([C] = [A] + [B] ➔ cij = aij + bij) and subtraction ([E] = [A] – [B] ➔ eij = aij - bij).
• Both addition and subtraction are commutative: [A] + [B] = [B] + [A].
• Both addition and subtraction are associative: ([A] + [B]) + [C] = [A] + ([B] + [C]).
• Multiplying a matrix with a scalar: The multiplication of a matrix [A] by a scalar g is obtained by multiplying every
element of [A] by g.
Matrix Algebra Overview: Matrix Operating Rules

• The product of two matrices is represented as [C] = [A][B], where the elements of [C] are defined as

• If the dimensions of the matrices are suitable, matrix multiplication is associative: ([A][B]) [C] = [A]([B][C]).
• matrix multiplication is distributive: [A]([B] + [C]) = [A][B] + [A][C].
• However, multiplication is not generally commutative: [A][B] ≠ [B][A]. That is, the order of matrix multiplication is
important.
Matrix Algebra Overview: Matrix Operating Rules

• Matrix division is not a defined operation. However, if a matrix [A] is square and nonsingular, there is another
matrix [A]−1, called the inverse of [A], for which
[A][A]−1 = [A]−1[A] = [I]
• A-1 = Adj(A)/det(A). The inverse of a 2 × 2 matrix can be represented simply by

• The transpose of a matrix [A]T involves transforming its rows into columns and its columns into rows. In other
words, the element aij of the transpose is equal to the aji element of the original matrix.
• A permutation matrix (also called a transposition matrix) is an identity matrix with rows and columns
interchanged. For example, here is a permutation matrix that is constructed by switching the first and third rows
or the first and third columns of a 3 × 3 identity matrix:
Matrix Algebra Overview: Matrix Operating Rules

• Left multiplying a matrix [A] by this matrix, as in [P][A], will switch the corresponding rows of [A]. Right
multiplying, as in [A][P], will switch the corresponding columns. Here is an example of left multiplication:

• The final matrix manipulation is augmentation. A matrix is augmented by the addition of a column (or columns)
to the original matrix. For example, suppose we have a 3 × 3 matrix of coefficients. We might wish to augment
this matrix [A] with a 3 × 3 identity matrix to yield a 3 × 6 dimensional matrix, written as [A|I]:

Such an expression has utility when we must perform a set of identical operations on the rows of two matrices.
Thus, we can perform the operations on the single augmented matrix rather than on the two individual matrices.
Example: MATLAB Matrix Manipulations

• Problem Statement.
• The following example illustrates how a variety of matrix manipulations are implemented with MATLAB. It is best
approached as a hands-on exercise on the computer.
>> A = [1 5 6;7 4 2;-3 6 7] % Create a 3 × 3 matrix >> D = [1 4 3;5 8 1]; % create a 2 × 3 matrix
>> A’ % The transpose of [A] >> A * D ➔ ??? Error using ==> mtimes,
Inner matrix dimensions must agree.
• Create another 3 × 3 matrix on a row basis: >> D * A
>> x = [8 6 9]; >> AI = inv(A) % Gives the inverse of A
>> I = eye(3) % create a 3 × 3 identity matrix
>> y = [-5 8 1];
>> P = [0 0 1;0 1 0;1 0 0]
>> z = [4 8 2]; >> PA = P*A % switch the rows
>> B = [x; y; z] >> AP = A * P % switch the columns
>> Aug = [A I] % Matrix augmentation
>> C = A + B % add [A] and [B] together >> [n,m] = size(Aug) % Matrix size
>> A = C – B
>> A * B
>> A.* B % element-by-element multiplication
Matrix Algebra Overview: Representing Linear
Algebraic Equations in Matrix Form
• Representing simultaneous linear equations. For example, a 3 × 3 set of linear equations,
a11x1 + a12x2 + a13x3 = b1
a21x1 + a22x2 + a23x3 = b2
a31x1 + a32x2 + a33x3 = b3
• can be expressed as [A]{x} = {b}, where [A] is the matrix of coefficients:

• A formal way to obtain a solution using matrix algebra is to multiply each side of the equation by the inverse of
[A] to yield: [A]−1[A]{x} = [A]−1{b} ➔ {x} = [A]−1{b}.
• It should be noted that systems with more equations (rows) than unknowns (columns), m > n, are said to be
overdetermined. A typical example is least-squares regression where an equation with n coefficients is fit to m
data points (x,y).
• Conversely, systems with less equations than unknowns, m < n, are said to be underdetermined. A typical
example of underdetermined systems is numerical optimization.
Solving Linear Algebraic Equations with
MATLAB
• MATLAB provides two direct ways to solve systems of linear algebraic equations.
• The most efficient way is to employ the backslash, or “left-division,” operator as in
>> x = A\b
• The second is to use matrix inversion:
>> x = inv(A)*b
• The matrix inverse solution is less efficient than using the backslash.
Bungee Jumper Problem

• Three jumpers are connected vertically by bungee cords at an initial distances, x1, x2, and x3. Compute the
displacement of each of the jumpers after they were released?
• Using Newton’s second law, force balances can be written for each jumper:

• where mi = the mass of jumper i (kg), t = time (s), kj = the spring


constant for cord j (N/m), xi = the displacement of jumper i
measured downward from the equilibrium position (m), and g
= gravitational acceleration (9.81 m/s2).
• Because we are interested in the steady-state solution, the
second derivatives can be set to zero.
• Collecting terms gives:
Example: Solving the Bungee Jumper Problem
with MATLAB
• Problem Statement.
• Use MATLAB to solve the bungee jumper problem described in the previous slide.
The parameters for the problem are:
Example: Solving the Bungee Jumper Problem
with MATLAB
• Solution. Substituting these parameter values into the equations in slide 12, gives:

>> K = [150 −100 0;−100 150 −50;0 −50 50]


➔ K = 150 −100 0; −100 150 −50; 0 −50 50
>> mg = [588.6; 686.7; 784.8]
➔ mg = 588.6000; 686.7000; 784.8000
• Employing left division yields
>> x = K\mg
➔ x = 41.2020; 55.9170; 71.6130
Example: Solving the Bungee Jumper Problem
with MATLAB
• Alternatively, multiplying the inverse of the coefficient matrix by the right-hand-side vector gives the same
result:
>> x = inv(K)*mg
➔x = 41.2020; 55.9170; 71.6130
• Because the jumpers were connected by 20-m cords, their initial positions relative to the platform is
>> xi = [20;40;60];
• Thus, their final positions can be calculated as:
>> xf = x+xi
➔xf = 61.2020; 95.9170; 131.6130
• The results show that the first cord is extended the longest because it has a lower spring constant
and is subject to the most weight (all three jumpers).
• Notice that the second and third cords are extended about the same amount. Because it is subject to
the weight of two jumpers, one might expect the second cord to be extended longer than the third.
However, because it is stiffer (i.e., it has a higher spring constant), it stretches less than expected
based on the weight it carries.
Case Study: Currents and Voltages in Circuits

• Background. A common problem in electrical engineering involves determining the currents and voltages at
various locations in resistor circuits. These problems are solved using Kirchhoff’s current and voltage rules. The
current (or point) rule states that the algebraic sum of all currents entering a node must be zero, or Σ i = 0.
• The voltage (or loop) rule specifies that the algebraic sum of the potential differences (i.e., voltage changes) in
any loop must equal zero. For a resistor circuit, this is expressed as Σ Vemf − Σ iR = 0.
Case Study: Currents and Voltages in Circuits

Solution.

You might also like