CSCI6370: Topics in Computer Science Advanced Topics in

Download Report

Transcript CSCI6370: Topics in Computer Science Advanced Topics in

Lecture 28: Mathematical
Insight and Engineering
Matrices
Matrices are commonly used in engineering
computations.
A matrix generally has more than one row and
more than one column.
Scalar multiplication and matrix addition and
subtraction are performed element by element.
Matrix Operations
Transpose
Multiplication
Exponentiation
Inverse
Determinants
Left division
Transpose
In mathematics texts you will often see
the transpose indicated with superscript T

AT
The MATLAB syntax for the transpose is

A'
The transpose switches the rows
and columns
1 2 3
4 5 6

A
7 8 9


10 11 12
1 4 7 10
AT  2 5 8 11
3 6 9 12
Dot Products
The dot product is sometimes called the
scalar product
The sum of the results when you
multiply two vectors together, element
by element.
* *
*
||
||
||
+
+
Equivalent
statements
Matrix Multiplication
Matrix multiplication results in an array
where each element is a dot product.
In general, the results are found by
taking the dot product of each row in
matrix A with each column in Matrix B
A: m x n
B: n x p
n
C(i, j)   A(i,k) * B(k, j)
k1

Because matrix multiplication is a
series of dot products


the number of columns in matrix A
must equal the number of rows in
matrix B
For an mxn matrix multiplied by an
nxp matrix
These dimensions must match
mxn
nxp
The resulting matrix will have
these dimensions
Matrix Powers
Raising a matrix to a power is
equivalent to multiplying itself the
requisite number of times
 A2 is the same as A*A
 A3 is the same as A*A*A
Raising a matrix to a power requires it
to have the same number of rows and
columns
Matrix Inverse
MATLAB offers two approaches

The matrix inverse function
 inv(A)

Raising a matrix to the -1 power
 A-1
Equivalent
approaches to
finding the inverse
of a matrix
A matrix times its
inverse is the identity
matrix
Not all matrices have an inverse
Called


Singular
Ill-conditioned matrices
Attempting to take the inverse of a
singular matrix results in an error
statement
Determinants
Related to the matrix inverse
If the determinant is equal to 0, the
matrix does not have an inverse
The MATLAB function to find a
determinant is

det(A)
|A| = A(1, 1)*A(2, 2)
- A(1, 2)*A(2, 1)
|A| = A(1,1)*A(2,2)*A(3,3)
+ A(1, 2)*A(2,3)*A(3,1)
+ A(1,3)*A(2,1)*a(3,2)
- A(3,1)*A(2,2)*A(1,3)
- A(3,2)*A(2,3)*A(1,1)
- A(3,3)*A(2,1)*A(1,2)
Solutions to Systems of Linear
Equations
3x 2 y
x
x
 z  10
3y 2 z  5
 y  z  1
Using Matrix Nomenclature
 3 2  1
 x
A   1 3 2  X   y 
 z 
 1  1  1
and
AX=B
10 
B   5 
 1
We can solve this problem using the
matrix inverse approach
This approach is easy
to understand, but its
not the more efficient
computationally
Matrix left division
uses Gaussian
elimination, which is
much more efficient,
and less prone to
round-off error
Practice Question
Q. Wh at is the output of the followin g code fragment?
int j;
for (j = 0 ; j < 4; j++) {
printf(“%d ”, j);
j++;
}
A)
B)
C)
D)
0123
02
13
123
Solution: B
Practice Question
Q. Wh at is the output of the followin g progra m?
#include <stdio.h>
int myFunc(int a, int *b);
int main( void ) {
int a = 4;
int b = 5;
myFunc(a, &b);
printf ("a + b = %d
\n", a + b);
}
int myFunc(int a, int *b) {
a = a + 2;
*b = *b - 1;
return a;
}
+
+
+
+
b
b
b
b
=
=
=
=
9
8
11
10
Solution: B
A) a
B) a
C) a
D) a